【发布时间】:2015-08-04 12:16:47
【问题描述】:
我需要从在电子表格中运行的 64 位 VBA 代码获取 Excel 2013 x64 窗口句柄。有几个选项可以做到这一点:
- 阅读
Application.Hwnd(MSDN Application.Hwnd Property (Excel)) - 调用 FindWindow,从 user32 导入,例如如此处接受的答案所述:What are the differences between VBA 6.0 and VBA 7.0?:
问题在于Application.Hwnd 返回一个Long,即32 位(我已经在64 位环境中使用MsgBox TypeName(Application.Hwnd) 验证了这一点),而FindWindow 返回一个LongPtr,即64 位在 Office x64 中长。
这是否意味着不能相信 Application.Hwnd 属性在 64 位环境中始终正确?
【问题讨论】:
-
没关系,窗口句柄在 64 位代码中仍然可以作为 32 位值工作。无论如何,高 32 位始终为 0。
-
true@HansPassant。 Msdn Ref:我帖子中的最后一个链接。
标签: vba excel 64-bit window-handles