问题描述
所以我忙于制作 SSIS 包,我需要在 excel 文档中运行宏,我只是不知道 VB 或如何在脚本任务中对此进行编码.
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.
我有一个名为 DATA.xlsm 的 excel 文档,其中包含一个名为Formatting"的宏
I have an excel document called something like DATA.xlsm with a Macro called "Formatting"
我只需要一个脚本任务,在 DATA.xlsm 中运行这个格式化宏,然后保存新的更新文档.
I just need to have a script task that runs this formatting macro in DATA.xlsm and then saves the new updated document.
感谢任何帮助.
我看过其他帖子,但没有一个真正有帮助,或者看起来比我想要做的更复杂.
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.
推荐答案
这里是 C# 中运行宏的基本骨架代码(必须添加对 Microsoft.Office.Interop.Excel 来完成这项工作)
Here is the basic skeleton code in C# to run a macro (you must add a reference to Microsoft.Office.Interop.Excel to make this work)
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();
这篇关于从 SSIS 运行 Excel 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!