我需要使用C#将一系列VBA子进程包含到Visio文档中,并在完成后调用其中一个。
我目前能够将宏添加到Visio文件中,但无法调用最近插入的Sub
//...
using Office = Microsoft.Office.Core;
using VBA = Microsoft.Vbe.Interop;
using Visio = Microsoft.Office.Interop.Visio;
//...
Visio.Application vsApp vsApp = new Visio.Application();
Visio.Document doc = vsApp.Documents.Open("filepath");
vsApp.Visible = true;
VBA.VBComponent oModule = doc.VBProject.VBComponents.Add(VBA.vbext_ComponentType.vbext_ct_StdModule);
String sCode =
"sub VBAMacro()\r\n" +
" msgbox \"VBA Macro called\"\r\n" +
"end sub";
// Add the VBA macro to the new code module.
oModule.CodeModule.AddFromString(sCode);
//HOW TO INVOKE VBAMacro ??
doc.Close();
vsApp.Quit();为了调用VBAMacro,我需要做什么?
发布于 2014-12-18 21:49:18
Visio在应用程序对象上没有Run方法,但是它有Document.ExecuteLine
'Executes the macro (procedure without an argument) named "SomeMacro"
'that is in some module of the Visual Basic project of ThisDocument.
ThisDocument.ExecuteLine("SomeMacro")
'Executes the procedure named SomeProcedure and passes it 3 arguments.
ThisDocument.ExecuteLine("SomeProcedure 1, 2, 3")
'Same as previous example, but procedure name qualified
'with module name.
ThisDocument.ExecuteLine("Module1.SomeProcedure 1, 2, 3")
'Shows the form UserForm1.
ThisDocument.ExecuteLine("UserForm1.Show")
'Prints "some string" to the Immediate window.
ThisDocument.ExecuteLine("Debug.Print ""some string""")
'Prints number of open documents to the Immediate window.
ThisDocument.ExecuteLine("Debug.Print Documents.Count")
'Tells ThisDocument to save itself.
ThisDocument.ExecuteLine("ThisDocument.Save") 来自:http://msdn.microsoft.com/en-us/library/office/ff765100(v=office.15).aspx
https://stackoverflow.com/questions/27555059
复制相似问题