How to connect to a running instance of outlook from C# [duplicate]

筅森魡賤 提交于 2019-12-06 08:09:39

问题


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?


回答1:


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

(See this related question.)



来源:https://stackoverflow.com/questions/15228845/how-to-connect-to-a-running-instance-of-outlook-from-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!