如何在 c# 中使用 Interop 将宏插入并运行到 word 文档中?
问问题
2645 次
1 回答
2
using System.Runtime.InteropServices;
using Microsoft.Vbe.Interop;
using Word = Microsoft.Office.Interop.Word.Application;
string file1, file2;
var word = new Word { Visible = true };
var doc = word.Documents.Open(file1);
var project = doc.VBProject;
var module = project.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
var script = string.Format(
@"Sub MacroTest()
Const path1 As String = ""{0}""
Set doc1 = Documents.Open(path1)
End Sub", file2);
module.CodeModule.AddFromString(script);
word.Run("MacroTest");
于 2017-08-17T07:35:14.943 回答