Return to Snippet

Revision: 70705
at June 13, 2016 20:05 by cueballrawn

Initial Code
Public Function OpenExcelTarget()
Dim xl As Object
    'Step 1:  Start Excel, then open the target workbook.
       Set xl = CreateObject("Excel.Application")
        xl.Workbooks.Open ("C:\Full_path_of_excel_file.xls")
    'Step 2:  Make Excel visible
       xl.Visible = True
    'Step 3:  Run the target macro
       xl.Run "ReplaceEmpty"
    'Step 4:  Close and save the workbook, then close Excel
       xl.ActiveWorkbook.Close (True)
    'Step 5:  Memory Clean up.
       Set xl = Nothing

End Function

Initial URL

Initial Description
This code allows you to open an Excel workbook from an Access database and run macros within the target workbook. This could be used to format / clean data prior to import for example.

Initial Title
Access (VBA) Open and run macro from an Excel workbook

Initial Tags

Initial Language
Visual Basic