Is it possible to use VBA in access to perform macros in excel, using a "call function"? I have am trying to format data, by using the VBA functions in Access.
1 Answer
Yes, it is possible.
Here is an example:
Sub RunExcelMacro()
Dim xl As Object
'Step 1: Start Excel, then open the target workbook.
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open ("C:\Book1.xlsm")
'Step 2: Make Excel visible
xl.Visible = True
'Step 3: Run the target macro
xl.Run "MyMacro"
'Step 4: Close and save the workbook, then quit the Excel application
xl.ActiveWorkbook.Close (True)
xl.Quit
'Step 5: Memory Clean up.
Set xl = Nothing
End Sub
1 Comment
autumntiger
Thank you! That works great! The only issue now, is that, I start with it closed because my boss wants as much automation as possible. When I run the code you gave me, it closed the wb immediately following the execution of the macro. Please advise.