查找 Office 应用程序的现有实例 [英] Find existing instance of Office Application
本文介绍了查找 Office 应用程序的现有实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法将 MS Publisher 的现有实例作为 Microsoft.Office.Interop.Publisher.Application
获取?
Is there any way to get existing instance of MS Publisher as Microsoft.Office.Interop.Publisher.Application
?
我发现了这个:
System.Diagnostics.Process.GetProcessesByName("Microsoft Publisher")
所以我可以检查它是否已经在运行,但是如何将其转换为 MS Publisher 应用程序?所以我可以调用 Microsoft.Office.Interop.Publisher.Application.Open
例如?
So I can check if this is already running, but how to convert it to MS Publisher application? So I can call Microsoft.Office.Interop.Publisher.Application.Open
for e.g.?
推荐答案
你可以试试这个 微软 getActiveObject.这是一个例子.
You could try this Microsoft getActiveObject. Here's an example.
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);
}
希望对我有所帮助!
这篇关于查找 Office 应用程序的现有实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文