vba 从 SSIS 运行 Excel 宏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20054131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run an Excel Macro from SSIS
提问by Luke K.
So Im busy making an SSIS package and I need to run a macro in an excel document, I just don't know VB or how I would code this in a Script Task.
所以我忙于制作 SSIS 包,我需要在 excel 文档中运行宏,我只是不知道 VB 或如何在脚本任务中对此进行编码。
I have an excel document called something like DATA.xlsm with a Macro called "Formatting"
我有一个名为 DATA.xlsm 之类的 excel 文档,其中包含一个名为“Formatting”的宏
I just need to have a script task that runs this formatting macro in DATA.xlsm and then saves the new updated document.
我只需要一个脚本任务,在 DATA.xlsm 中运行这个格式化宏,然后保存新的更新文档。
Any help is appreciated.
任何帮助表示赞赏。
Ive looked at other posts on this but none of them are really helpful, or seem more complicated than what I am trying to do.
我看过其他帖子,但没有一个真正有帮助,或者看起来比我想要做的更复杂。
回答by Kyle Hale
Here is the basic skeleton code in C# to run a macro (you must add a reference to Microsoft.Office.Interop.Excelto make this work)
这是在 C# 中运行宏的基本框架代码(您必须添加对Microsoft.Office.Interop.Excel的引用才能使其工作)
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook = xlApp.Workbooks.Open("C:\ExcelDirectory\DATA.xlsm"); // absolute path needed
xlApp.Run("Formatting"); // method overloads allow you to send it parameters, etc.
xlWorkBook.Close(true); // first parameter is SaveChanges
xlApp.Quit();