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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runn Excel Macros Thorugh Access 2

Status
Not open for further replies.

BradB

MIS
Jun 21, 2001
237
US
I want to click a button on a form, and run a macro that is in Excel. The following code will OPEN the document, but NOT run the macro. I have to manually click the macro button to work. Help!

Here's the code I borrowed from a website:

Code
Option Compare Database

Private Sub cmdImport_Click()
Dim objXL As Object, x
On Error Resume Next
Set objXL = CreateObject("Excel.Application")

With objXL.Application
.Visible = True
'Open the Workbook
.Workbooks.Open "H:\pwilliams\Personal\Import.xls"
'Include CARMA in menu, run AutoOpen
.activeworkbook.RunAutoMacro
x = .Run("import", 0)
End With

Set objXL = Nothing

End Sub
 
Try...

objXL.Run("Macroname")

Should work...

There are two ways to write error-free programs; only the third one works.
 
By the way, I don't suppose you know how to make Excel close after the macro is done?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top