Call outlook VBA from Excel

一个人想着一个人 提交于 2019-11-28 00:30:59

If you wish to get hold of a reference to an instance of Outlook that is already running, you will need to use:

Set myOutlookApp = GetObject(,"Outlook.Application")

which will give you access to the Outlook application object so you can call your desired VBA function in Outlook:

myOutlookApp.MyFunctionToExecute()

You'll probably need to make the function Public otherwise Excel's VBA might not be able to see it.

MS Office applications can interact with each other by this method (this is based on Office 2007, but others will be similar):

Add a reference to the app into Excel

In Excel VBA, from the Tools\References menu select Microsoft Outlook 12.0 Object Library

In your BeforeClose Event include

Dim olApp As Outlook.Application
Set olApp = New Outlook.Application

You can now access Outlook through the olApp object. I don't know much about the Outlook object model, so others may be able help more from here on...

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