从 Excel 调用 Outlook VBA [英] Call outlook VBA from Excel
问题描述
我想在某个 Excel 工作簿关闭时调用 Outlook VBA 中的一个函数.有没有办法用excel的BeforeClose事件来做到这一点?我知道如何为此事件编写函数,但我不确定如何将它们链接到当前的 Outlook 会话以访问该函数.
I have a function in the outlook VBA that I want to call when a certain excel workbook is closed. Is there a way to do this with the BeforeClose event of excel? I know how to write functions for this event, but I am not sure how to link them to the current outlook session to get to the function.
推荐答案
如果您希望获得对已在运行的 Outlook 实例 的引用,您需要使用:
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")
这将使您能够访问 Outlook 应用程序对象,以便您可以在 Outlook 中调用所需的 VBA 函数:
which will give you access to the Outlook application object so you can call your desired VBA function in Outlook:
myOutlookApp.MyFunctionToExecute()
您可能需要将函数设为 Public
,否则 Excel 的 VBA 可能无法看到它.
You'll probably need to make the function Public
otherwise Excel's VBA might not be able to see it.
这篇关于从 Excel 调用 Outlook VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!