I recently had to document the methods of a vast class module. Means I wanted the names of all public functions listed in the module itself in a special procedure to give the opportunity to call them by name (CallByName used; could also be DispCall).
I could use a VB6 documenter for this, but asked myself if there is any way to access the VB6 Extensibility Library from inside the IDE apart from using an add-in, which seems to be the only way to get the instance's VBE Application object - other than in VBA Office where you can access VBIDE at any time. Investigated all over the net but could not find any solution. So here is mine.
It's so small that I can post the only important code routine here:
Explanation:
Attached is a little project to demonstrate the usage. Hope it works in your environment.
If you want to implement this in your own project just copy the one routine and the API declarations into some module.
I could use a VB6 documenter for this, but asked myself if there is any way to access the VB6 Extensibility Library from inside the IDE apart from using an add-in, which seems to be the only way to get the instance's VBE Application object - other than in VBA Office where you can access VBIDE at any time. Investigated all over the net but could not find any solution. So here is mine.
It's so small that I can post the only important code routine here:
Code:
Private ThisVBE As VBIDE.VBE
Function GetVBIDE() As VBIDE.VBE
Dim hwndMain As Long
Dim sTitle As String
Dim ret As Long
Dim hProp As Long
Dim ObjW As Object
On Error GoTo ErrHandler
If ThisVBE Is Nothing Then
hwndMain = FindWindow("wndclass_desked_gsk", vbNullString)
If hwndMain <> 0 Then
sTitle = String(255, 0)
ret = GetWindowText(hwndMain, sTitle, 255)
If ret > 0 Then
sTitle = Left(sTitle, ret)
If InStr(1, sTitle, "Microsoft Visual Basic") > 0 Then
hProp = GetProp(hwndMain, "VBAutomation")
If hProp <> 0 Then
CopyMemory ObjW, hProp, 4& '= VBIDE.Window
Set ThisVBE = ObjW.VBE
CopyMemory ObjW, 0&, 4&
End If
End If
End If
End If
End If
Set GetVBIDE = ThisVBE
Exit Function
ErrHandler:
MsgBox Err.Description, vbCritical, "GetVBIDE()"
Resume Next
End Function
- With the help of some API functions receive the window of VB's IDE (class wndclass_desked_gsk; top level window)
- Check if it's the right one ('Microsoft Visual Basic' in caption)
- All IDE windows expose a windows property (long value) called "VBAutomation". I found out this to be the object pointer of the related VBIDE.Window
- Get the pointer with GetProp
- Turn the pointer into an object (CopyMemory)
- Get the root VBE from property Window.VBE
Attached is a little project to demonstrate the usage. Hope it works in your environment.
If you want to implement this in your own project just copy the one routine and the API declarations into some module.