Solved

Add In

Posted on 1998-07-15
3
320 Views
Last Modified: 2008-02-01
I would like to be able to enable and disable commandbar controls based on which window in the VB IDE is active (i.e. the codepane window) but I don't know of any objects which 'listen' for these events.
0
Comment
Question by:markmcc
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
tomook earned 100 total points
ID: 1465811
VB5 Add-Ins can do what you want. I assume you can create an Add-In from the New Project menu. Assuming you use the default template, go to the class "Connection" and put these two lines in the Declarations section:

Public WithEvents mVBComponentEvents As VBComponentsEvents
Public WithEvents mVBProjEvents As VBProjectsEvents

Near the top of IDTExtensibility_OnConnection, after the line
    Set VBInstance = VBInst
add:
    Set mVBProjEvents = VBInstance.Events.VBProjectsEvents
    If Not (VBInstance.ActiveVBProject Is Nothing) Then
        Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBInstance.ActiveVBProject)
    End If

Then add the following event handlers:
Private Sub mVBComponentEvents_ItemActivated(ByVal VBComponent As VBIDE.VBComponent)
    ' This is probably where you want to do your command bar manipulations.
    ' Check out the CommandBars property of the variable VBInstance.
    MsgBox "Activated component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemAdded(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Added component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemReloaded(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Reloaded component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemRemoved(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Removed component " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemRenamed(ByVal VBComponent As VBIDE.VBComponent, ByVal OldName As String)
    MsgBox "Renamed component " & OldName & " to " & VBComponent.Name
End Sub

Private Sub mVBComponentEvents_ItemSelected(ByVal VBComponent As VBIDE.VBComponent)
    MsgBox "Selected component " & VBComponent.Name
End Sub

Private Sub mVBProjEvents_ItemActivated(ByVal VBProject As VBIDE.VBProject)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

Private Sub mVBProjEvents_ItemAdded(ByVal VBProject As VBIDE.VBProject)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

Private Sub mVBProjEvents_ItemRemoved(ByVal VBProject As VBIDE.VBProject)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

Private Sub mVBProjEvents_ItemRenamed(ByVal VBProject As VBIDE.VBProject, ByVal OldName As String)
    Set mVBComponentEvents = VBInstance.Events.VBComponentsEvents(VBProject)
End Sub

The code here just pops up message boxes, but you can just as well manipulate command bars.
0
 

Author Comment

by:markmcc
ID: 1465812
I wanted to know which windows (codepane, property, toolbar, immediate, etc.) in the VB IDE was active not the components (forms, modules, classes etc).  I've found out that VB doesn't provide hooks in these events.  One way to do this, however, is to place a timer control on a form and use the ActiveWindow property of the VBE object.
0
 
LVL 4

Expert Comment

by:tomook
ID: 1465813
It looks like the VB team did not think anyone would want to know that. Good luck. Do you mind my asking what this is for?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question