IDE Add-In was created in VB6 and is intended for VB6, Excel, Access etc.
Looking on Application
& AddInInst
parameter, passed to initial procedure:
Private Sub AddinInstance_OnConnection( _
ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)
I can't found any explicit host value. Where I can get a reference to the host?
.
The host is not explicitly exposed by the VBIDE object model, but there are a number of approaches for getting a reference to the host:
Inspect the references for the vbProject. The host reference will typically be the 2nd reference for a project. Once you know the name of the reference, you can build a string for use with GetObject
. The problem is, if there isn't a VBProject loaded, or the project is protected, this method won't work.
Inspect the caption of the first button in the VBE's Standard CommandBar, which in the case of Excel is "View Microsoft Excel (Alt+F11)". Once you know the name of the host, you can build a string for use with GetObject
Use the Properties collection of a vbComponent such as
ThisWorkbook` to return a reference to the Application. This approach will only work if the project has a document-type vbComponent. Hosts like PowerPoint and Access don't necessarily have a document-type component. This approach also requires that there be at least one project open and unprotected:
Dim app As Excel.Application
Set app = _vbe.ActiveVBProject.VBComponents("ThisWorkbook").Properties("Parent").Object
Use Accessibility (GetAccessibleObject
) to get a handle tho the host from the ProcessID of the VBE (which you can get from the VBE's Hwnd). See the issue link below for more details.
Rubberduck has had to do the same thing for multiple hosts in a C# add-in for the VBE. Have a look at the source code on GitHub, and here and also this related issue