Access中的VBA调用函数

是否有可能使用VBA访问在Excel中执行macros,使用“调用函数”? 我正尝试通过在Access中使用VBA函数来格式化数据。

对的,这是可能的。

这里是一个例子:

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