如何在C#中从.docm文件调用宏?
答案在下面。
但是为了满足高质量的stackoverflow标准,我必须在此处写一个小题词以发布此问题。
using System.IO;
using Microsoft.Office.Interop.Word;
namespace OpenDocmMacro
{
class Program
{
static void Main(string[] args)
{
string file_path = "";
string macro_name = "";
Application ap = new Application();
Document document = new Document();
try
{
document = ap.Documents.Open(Path.GetFullPath(file_path));
ap.Run(macro_name);
}
catch
{
}
finally
{
document.Close();
ap.Quit();
}
}
}
}