如何连接到的展望从C#的运行实例 [英] How to connect to a running instance of outlook from C#

查看:166
本文介绍了如何连接到的展望从C#的运行实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VBA中,我通常使用 appOutlook = GetObject的(Outlook.Application)来获得的Outlook的运行实例,它抛出一个错误如果Outlook ISN吨运行。我通常这样做在Excel中,但现在我想看看我是否可以通过移动到C#,并从那里做它那里得到更好的效果。我需要做的是从Outlook电子邮件复制并粘贴到Excel中,这样的表中的电子邮件得到粘贴成S preadsheet为单元格的值,而不是HTML。不过,我不太清楚如何做到这一点。我通常使用 Activator.CreateInstance ,但它是一个新的实例。我怎样才能连接到Excel和Outlook中的当前实例?

In VBA, I usually use appOutlook = GetObject(, "Outlook.Application") to get a running instance of Outlook, and it throws an error if Outlook isn't running. I normally did this in excel, but now I am wanting to see if I can get better results by moving to C# and doing it from there. What I need to do is copy emails from outlook and paste them into excel so that the tables in the email get pasted into the spreadsheet as cell values rather than html. However, I'm not quite sure how to do this. I usually use Activator.CreateInstance, but it makes a new instance. How can I connect to the current instance of Excel and Outlook?

推荐答案

您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getactiveobject.aspx"相对=nofollow> System.Runtime.InteropServices.Marshal.GetActiveObject() 用于这一目的。

You can use System.Runtime.InteropServices.Marshal.GetActiveObject() for this purpose.

(请参见此相关的问题。)

这篇关于如何连接到的展望从C#的运行实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆