![](/img/trans.png)
[英]How can we run the excel macro of an existing Excel sheet using C#?
[英]Run a macro in excel sheet using c#
嗨,朋友们,我正在研究vss 2012,Excel2013。我正在尝试将表格视图记录导出到Excel工作表。 Excel工作表将是很好的样式。 所以我要做的是在一个Excel工作表中创建了我的设计宏。 所以现在我有了那个特定宏的代码。
现在我也想在新的Excel工作表中使用此宏(设计)。 就像说每天都会将新记录添加到网格视图中一样,在一天结束时,如果我单击“导出到excel”,那么应该使用宏和所有记录的设计来创建新的excel。 那可能吗??
实施此过程可能会有什么困难。.我在网上找不到与此相关的任何内容。 所以,如果有人知道这一点,请告诉我...
您可以使用以下代码插入VBA宏:
public void SetVBACode(string _macro)
{
VBProject project = workbook.VBProject;
VBComponents components = project.VBComponents;
VBComponent component =components.Add(vbext_ComponentType.vbext_ct_StdModule);
component.CodeModule.AddFromString(_macro);
}
并使用以下方法运行它们:
public void RunVBACode(string _name)
{
excelApplication.RunVBACode(_name);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.