2

有没有办法将现有的 MS Publisher 实例获取为Microsoft.Office.Interop.Publisher.Application

我发现了这个:

System.Diagnostics.Process.GetProcessesByName("Microsoft Publisher")

所以我可以检查它是否已经在运行,但是如何将它转换为 MS Publisher 应用程序?所以我可以打电话Microsoft.Office.Interop.Publisher.Application.Open给例如?

4

1 回答 1

8

你可以试试这个Microsoft getActiveObject。这是一个例子。

    object word;
    try
    {
        word = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
//If there is a running Word instance, it gets saved into the word variable
    }
    catch (COMException)
    {
//If there is no running instance, it creates a new one
        Type type = Type.GetTypeFromProgID("Word.Application");
        word = System.Activator.CreateInstance(type);
    }

希望我有帮助!

于 2015-07-11T21:17:44.433 回答