Solved

Add In

Posted on 1998-07-15
3
314 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now