从 Office 应用程序外部访问 VBA 公共变量

问题描述 投票:0回答:1

我有设置公共变量的 Outlook VBA 代码,并尝试通过 Outlook 的 COM 接口从外部访问该值。这可能吗?

具体来说,我在 AutoHotkey 中使用 ComObjActive 函数,但找不到任何有关如何读取 Project1->Microsoft Outlook Objects->ThisOutlookSession VBA 代码中设置的变量值的文档。

如果有更好的方法来处理这种情况——本质上是促进 AutoHotkey 脚本和 Outlook VBA 之间的双向通信——我会很高兴听到。

vba outlook autohotkey
1个回答
0
投票

供将来参考,在 Outlook VBA 中:

Public myStorage As Outlook.StorageItem
Set myStorage = Application.Session.GetDefaultFolder(olFolderInbox).GetStorage("myStorage", olIdentifyBySubject)
myStorage.UserProperties.Add "myValue", olNumber
myStorage.UserProperties("myValue").Value = 1
myStorage.Save

然后在 AutoHotkey 中:

Outlook := ComObjActive("Outlook.Application")
x := Outlook.Session.GetDefaultFolder(6).GetStorage("myStorage",0).UserProperties("myValue").value
© www.soinside.com 2019 - 2024. All rights reserved.