简体   繁体   English

Access中的VBA调用函数

[英]VBA Call Function in Access

Is it possible to use VBA in access to perform macros in excel, using a "call function"?是否可以使用 VBA 访问以使用“调用函数”在 excel 中执行宏? I have am trying to format data, by using the VBA functions in Access.我试图通过使用 Access 中的 VBA 函数来格式化数据。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM