3

I'm writing a VBE/VBIDE add-in and I have a tool window that changes based on the open CodePane objects. Is there an event I can monitor when a code pane is added or removed from the CodePanes collection?

The CodePanes collection itself appears to have no Events associated with it.

If there is no event available, I'm open to other workarounds. Polling would be a reliable fallback, but I'd rather not go that route if I could avoid it.

mwolfe02
  • 23,787
  • 9
  • 91
  • 161
  • This [Q&A](https://stackoverflow.com/q/29882916/154439) from @Mat'sMug is related, but different. That question specifically refers to the [VBProjects](https://msdn.microsoft.com/en-us/library/aa443986(v=vs.60).aspx) collection, which *does* have events associated with it. – mwolfe02 Jun 06 '17 at 13:57
  • That sounds like fun! Actually, I may have found what I was looking for. The [VBComponents collection](https://msdn.microsoft.com/en-us/library/aa443983(v=vs.60).aspx) has several events that I may be able to use. – mwolfe02 Jun 06 '17 at 14:06
  • I thought I could use the [ItemActivated event](https://msdn.microsoft.com/en-us/library/aa445382(v=vs.60).aspx). I'm assuming that event is triggered whenever a new code module window is activated. At that point, I can just run through all the items in the CodePanes collection to rebuild my control. Or am I misunderstanding when that event will fire? – mwolfe02 Jun 06 '17 at 14:25
  • Hmm, that might work, but then you could possibly (not sure) end up with edge cases where a code pane is closed from its control box, or user selects "hide" from the context menu: MSDN is unclear on whether the event gets fired in these cases. – Mathieu Guindon Jun 06 '17 at 14:29
  • @mwolfe02 you can't rely on the ItemActivated event for modules that have designers (eg Forms, Worksheets, Access Reports etc), as the ItemActivated event won't tell you if it is the CodePane or the designer that is activated. You might activate the designer, and yet have a different module's codepane as the topmost codepane. I wrote and tested the logic of the VBE's window activation in Rubberduck, and it was non-trivial. – ThunderFrame Jun 30 '17 at 05:06
  • @Thunderframe yes, I'm finding that out ;-) – mwolfe02 Jun 30 '17 at 11:08

0 Answers0