从SSIS运行Excel宏 [英] Run an Excel Macro from SSIS

查看:151
本文介绍了从SSIS运行Excel宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在做一个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看在其他帖子上,但没有一个是真正有用的,或者似乎比我想要做的更复杂。

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宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆