Experimenting With the Extensibility Model
See Also
Once you become more familiar with the extensibility model, it can help to experiment with the various properties, methods and events contained in it. The following is one way to do this:
-
Start Visual Basic and choose Addin as the project type in the New Project dialog.
-
In the Visual Basic Project window, double click on the Connect class module to view its code.
-
Use Find from the Edit menu to search for OnConnection. This should place the cursor in the IDTExtensibility_OnConnection procedure.
-
There is a comment 3 or 4 lines into the procedure suggesting that the following statement is a good place to put a breakpoint for testing code. Place a breakpoint on the suggested line.
-
Place your cursor in the Immediate window, type
AddToIni
, then press Enter to execute that procedure. (AddToIni is a procedure in the module Addin.Bas.)
-
Press F5 to put the Addin into Run mode.
-
Start another instance of Visual Basic. Choose the default (Standard Exe) from the initial dialog, then choose Add-In Manager from the Add-Ins menu.
-
Check My Addin-In on the list of Available Add-Ins. Press OK in the Add-In Manager dialog. The IDTExtensibility_OnConnection is called in the first instance of Visual Basic, and execution is suspended at the breakpoint that you set in step #4.
-
Use Step Into from the debug menu to execute the line:
Debug.Print VBInst.FullName
Notice that the path and name of the current instance of Visual Basic is printed in the Immediate window.
-
You can now use VBInst as the object for the example code. Simply replace the dummy object Application.VBE with the Visual Basic object VBInst before executing the example lines in the Immediate window.
For example, you can modify the example:
Print Application.VBE.VBProjects(1).VBComponents.Count
to read as follows:
Print VBInst.VBProjects(1).VBComponents.Count
When you press Enter on the latter line in the Immediate window, the number of Visual Basic components is printed on the next line.
You now can experiment with various methods and properties in the Immediate window.