查找现有的 Office 应用程序实例

3

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

我找到了这个:

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

我可以检查它是否正在运行,但是如何将其转换为MS Publisher应用程序?这样我就可以调用Microsoft.Office.Interop.Publisher.Application.Open,对吧?


请问您能否澄清一下,您所说的"调用 Application.Open"是什么意思?您需要做些什么? - ninjaboy
搜索术语 - ROT(运行对象表) - Alexei Levenkov
1个回答

9
你可以尝试使用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);
    }

希望我能帮上忙!

我可以用这种方式将object作为Microsoft.Office.Interop.Word.Application使用吗? - Michał Woliński
我很高兴能帮助到你! - McLinux
Microsoft getActiveObject的链接已损坏。这是正确的链接:Marshal.GetActiveObject - Yeshurun Kubi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接