|
可以使用Windows API函数FindWindow或FindWindowEx获取VBE窗口的句柄。具体步骤如下:
使用FindWindow函数查找VBE主窗口的句柄,主窗口类名为"wndclass_desked_gsk"。
使用FindWindowEx函数查找VBE编辑窗口的句柄,编辑窗口类名为"EXCEL7"。
以下是示例代码:
复制
Option Explicit
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As LongPtr, ByVal hWndChildAfter As LongPtr, ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Sub GetVBEWindowHandle()
Dim hwndVBE As LongPtr
Dim hwndEditor As LongPtr
'获取VBE主窗口句柄
hwndVBE = FindWindow("wndclass_desked_gsk", vbNullString)
If hwndVBE <> 0 Then
'获取VBE编辑窗口句柄
hwndEditor = FindWindowEx(hwndVBE, 0, "EXCEL7", vbNullString)
If hwndEditor <> 0 Then
MsgBox "VBE编辑窗口句柄为:" & hwndEditor
Else
MsgBox "未找到VBE编辑窗口"
End If
Else
MsgBox "未找到VBE主窗口"
End If
End Sub |
评分
-
1
查看全部评分
-
|