Run macro within a macro

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I can open an excel worksheet with a cmd button in access,
but how do I then run the macro contained inside that
worksheet?? I want to open the excel and run the macro
with the click of the command button...
 
In VBA, you could do something similar to this:


Dim xls As Object, xwkb As Object
Dim strFile As String, strMacro As String
strFile = "Ken.xls"
strMacro = "Testing1"
' Export the table
DoCmd.TransferSpreadsheet acExportDelim, , "TableName", "C:\" & strFile
Set xls= CreateObject("Excel.Application")
xls.Visible = True
Set xwkb = xls.Workbooks.Open("C:\" & strFile)
xls.Run strFile & "!" & strMacro
xwkb.Close False
Set xwkb = Nothing
xls.Quit
Set xls = Nothing
End Sub
 
Back
Top