Access(VBA)从Excel工作簿打开并运行宏
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Access(VBA)从Excel工作簿打开并运行宏相关的知识,希望对你有一定的参考价值。
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.
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) xl.Quit 'Step 5: Memory Clean up. Set xl = Nothing End Function
以上是关于Access(VBA)从Excel工作簿打开并运行宏的主要内容,如果未能解决你的问题,请参考以下文章
使用 vba 将 MS Access 查询输出到 Excel
Excel 2010 vba 复制选择工作表,保存并关闭两个工作簿
“共享工作簿”模式下不支持 Excel VBA QueryTable