查找Office应用程序的现有实例
本文关键字:实例 Office 应用程序 查找 | 更新日期: 2023-09-27 18:02:11
是否有办法获得MS Publisher作为Microsoft.Office.Interop.Publisher.Application
的现有实例?
我发现了这个:
System.Diagnostics.Process.GetProcessesByName("Microsoft Publisher")
所以我可以检查这是否已经运行,但如何将其转换为MS Publisher应用程序?所以我可以把Microsoft.Office.Interop.Publisher.Application.Open
称为。
你可以试试这个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);
}
希望我有帮助!