Note: Change the Security Level for Access Macro, otherwise whenever the SSIS package
executes, it will popup a Security Warning Message. To avoid this, follow the instructions:
Open Access -- > Tools --> Macro --> Security
Click Security and change to Low Level.
Introduction
Basically to execute Access Macros in SSIS package, we need to download Microsoft.Office.Interop.Access DLL from Office XP PIAs. The file can be downloaded from the link at the top of this article.
Using the code
- Extract the Microsoft.Office.Interop.Access DLL from Oxppia.exe
- Drag and Drop Microsoft.Office.Interop.Access DLL to Global Assembly Directory(GAC)
- C:\WINNT\assembly for Windows 2000
- C:\WINDOWS\assembly for Windows XP and Windows 2003
- 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 for Windows XP and Windows 2003
- Add DLL reference in the Script Task
- Add the code given below
- Create a New Project in SSIS
- Drag and Drop the Script Task
- 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)
objAccess.DoCmd.RunMacro("Macro1")
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