Showing posts with label macro. Show all posts
Showing posts with label macro. Show all posts

Friday, March 30, 2012

Running Access XP Macro with script task

I found this and have done everything it says to do, but I can't get the script to compile. Any ideas on how to run a access macro in SSIS?

Baiscally to execute an Access Macros in SSIS package we need to Download

Microsoft.Office.Interop.Access DLL from Office XP PIAs.

Download site

http://www.microsoft.com/downloads/details.aspx?FamilyId=C41BD61E-3060-4F71-A6B4-01FEBA508E52&displaylang=en

1) Extract the Microsoft.Office.Interop.Access DLL from Oxppia.exe

2) Drag and Drop Microsoft.Office.Interop.Access DLL to Global Assembley Directory(GAC) ie: C:\WINNT\assembly for Windows 2000 -- C:\WINDOWS\assembly for ( Win Xp and Win 2003)

3) Copy paste Microsoft.Office.Interop.Access to C:\WINNT\Microsoft.NET\Framework\v2.0.50727 for Windows 2000 -- C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 ( Win Xp and Win 2003)

4) Add DLL reference in the Script Task

5) Add the below Code

1) Create a New Project in SSIS

2) Drag and Drop Script Task

3) Copy Paste the code in script task editor

Imports Microsoft.Office.Interop.Access

Try

Dim objAccess As New Access.Application

objAccess.OpenCurrentDatabase("D:\TestMacro.mdb", False) ' Add the Access File Path

objAccess.DoCmd.RunMacro("Macro1") ' Replace Macro1 with the name of your macro

objAccess.CloseCurrentDatabase()

objAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

objAccess = Nothing

Catch ex As Exception

System.Windows.Forms.MessageBox.Show(ex.ToString())

End Try

Dts.TaskResult = Dts.Results.Success

I actually figured this out. Had to reference alot more than just the access dll. Below is the final code to get it to work if anyone else wants to do something like this.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.Office.Interop.Access

Imports ADODB

Imports dao

Imports mscomctl

Imports msdatasrc

Imports stdole

Imports Microsoft.Office.Interop

Imports Microsoft.Office.Interop.OWC

PublicClass ScriptMain

' The execution engine calls this method when the task executes.

' To access the object model, use the Dts object. Connections, variables, events,

' and logging features are available as static members of the Dts class.

' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

'

' To open Code and Text Editor Help, press F1.

' To open Object Browser, press Ctrl+Alt+J.

PublicSub Main()

'

Try

Dim objAccess AsNew Access.Application

objAccess.OpenCurrentDatabase("D:MyDB.mdb", False) ' Add the Access File Path

objAccess.DoCmd.RunMacro("Macro1") 'Add your Macro name

objAccess.CloseCurrentDatabase()

objAccess.Quit(Access.AcQuitOption.acQuitSaveNone)

objAccess = Nothing

Catch ex As Exception

System.Windows.Forms.MessageBox.Show(ex.ToString())

EndTry

Dts.TaskResult = Dts.Results.Success

EndSub

EndClass

Friday, March 9, 2012

Run Excel macro from SQL Server Agent

Hi,
I have a DTS package that (among other things) runs an Excel macro.
The macro pulls in data from the server, formats it, then saves the
workbook to a network drive. The package runs fine when executed
locally but will not run as a scheduled job since Excel is not
installed on the server. I need to be able to schedule this job
somehow, and as you can imagine, the DBA and network admins are not
about to install Office on the server. Is there a way around this?Without OLE automation (i.e. *.dll) you would not be able to run the macro.
I don't think there is a way without installing the component on the server.
--
-oj
<jono@.mailinator.com> wrote in message
news:1123803060.725514.253790@.z14g2000cwz.googlegroups.com...
> Hi,
> I have a DTS package that (among other things) runs an Excel macro.
> The macro pulls in data from the server, formats it, then saves the
> workbook to a network drive. The package runs fine when executed
> locally but will not run as a scheduled job since Excel is not
> installed on the server. I need to be able to schedule this job
> somehow, and as you can imagine, the DBA and network admins are not
> about to install Office on the server. Is there a way around this?
>

Run Excel macro from SQL Server Agent

Hi,
I have a DTS package that (among other things) runs an Excel macro.
The macro pulls in data from the server, formats it, then saves the
workbook to a network drive. The package runs fine when executed
locally but will not run as a scheduled job since Excel is not
installed on the server. I need to be able to schedule this job
somehow, and as you can imagine, the DBA and network admins are not
about to install Office on the server. Is there a way around this?
Without OLE automation (i.e. *.dll) you would not be able to run the macro.
I don't think there is a way without installing the component on the server.
-oj
<jono@.mailinator.com> wrote in message
news:1123803060.725514.253790@.z14g2000cwz.googlegr oups.com...
> Hi,
> I have a DTS package that (among other things) runs an Excel macro.
> The macro pulls in data from the server, formats it, then saves the
> workbook to a network drive. The package runs fine when executed
> locally but will not run as a scheduled job since Excel is not
> installed on the server. I need to be able to schedule this job
> somehow, and as you can imagine, the DBA and network admins are not
> about to install Office on the server. Is there a way around this?
>

Run Excel macro from SQL Server Agent

Hi,
I have a DTS package that (among other things) runs an Excel macro.
The macro pulls in data from the server, formats it, then saves the
workbook to a network drive. The package runs fine when executed
locally but will not run as a scheduled job since Excel is not
installed on the server. I need to be able to schedule this job
somehow, and as you can imagine, the DBA and network admins are not
about to install Office on the server. Is there a way around this?Without OLE automation (i.e. *.dll) you would not be able to run the macro.
I don't think there is a way without installing the component on the server.
-oj
<jono@.mailinator.com> wrote in message
news:1123803060.725514.253790@.z14g2000cwz.googlegroups.com...
> Hi,
> I have a DTS package that (among other things) runs an Excel macro.
> The macro pulls in data from the server, formats it, then saves the
> workbook to a network drive. The package runs fine when executed
> locally but will not run as a scheduled job since Excel is not
> installed on the server. I need to be able to schedule this job
> somehow, and as you can imagine, the DBA and network admins are not
> about to install Office on the server. Is there a way around this?
>

Run DTS Package from Visual Basic 6.3

Anyone have any code i can use to call a DTS package from Visual Basic. I would like to have an outlook macro that will run a dts package when i receive an email. All i need is the code that will call a dts package for a sql server that is not local to the box. I've tried this code but i get an error
run_tmie error '-2147217900 (80040e14)' automation error

Public Sub main()

Dim oPkg As DTS.Package2
Set oPkg = New DTS.Package2

oPkg.LoadFromSQLServer MyServerName, MyUserName, MyPassword, , MyDTSPackageName

oPkg.Execute
oPkg.UnInitialize

Set oPkg = Nothing

End Sub


Thanks in advance.I use the following in a VBScript. Will work in VB also.

strDTSRun_Command = "dtsrun.exe /Sservername /E /Ndtspackagename"
iWindowStyle = 10
bWaitOnReturn = true
Return = WshShell.Run(strDTSRun_Command, iWindowStyle, bWaitOnReturn)