To execute a package first you need to load the package into an object, then simply use object.Execute method. To use the DTS objects enable the reference to the Microsoft DTSPackage Object Library. Here is an example for a server package.
Sub Main() Dim oPKG As New DTS.Package oPKG.LoadFromSQLServer "Server", , , 256, , , , "PackageName" oPKG.Execute oPKG.UnInitialize Set oPKG = Nothing End Sub
Error checking should also form a part of any execution routine.
For this I'd recommend reading the Microsoft Knowledge Base Article:
For those that want more control, you can declare the package object WithEvents.
This gives you progress and error events as they happen. It also allows you to
cancel execution in a similar method to that used by the Enterprise Manager execution interface.
For more information about WithEvents and DTS, see the Microsoft Knowledge Base Article:
A limitation of executing packages from Visual Basic is the need to ensure all steps execute in the main thread.
Sub Main() Dim oPKG As New DTS.Package oPKG.LoadFromSQLServer "Server", , , 256, , , , "PackageName" ' Set ExecuteInMainThread for ALL Steps Dim i As Integer For i = 1 To oPKG.Steps.Count oPKG.Steps(i).ExecuteInMainThread = True Next i oPKG.Execute oPKG.UnInitialize Set oPKG = Nothing End Sub