Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running Excel Macro from Access

Status
Not open for further replies.

clifftech

ISP
Nov 9, 2001
111
US
Please help.

I am trying to run an Excel macro from an Access command button with this code:

Private Sub Run_xlMacro_Click()

Dim objXLApp As Excel.Application
Dim objXLWB As Excel.Workbook
Dim strMacro As String

Set objXLApp = CreateObject("Excel.Application")

Set objXLWB = GetObject("S:\Projects\template.xlsm")

objXLApp.Run ("template.xlsm!msgtest")

objXLApp.Quit

End Sub

I'm getting the error - Method 'Run' of object'_Application'failed.


I'm using Office 2007 and for references in Access have "Microsoft Excel 12.0 Object Library" checked. The macro in Excel is for bring up a simple message box. What am I leaving out?
 
Replace this:
Set objXLWB = GetObject("S:\Projects\template.xlsm")
with this:
objXLApp.Workbooks.Open "S:\Projects\template.xlsm"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top