![]() |
Active VBE Module ?
I wish to execute a macro while in the VBE and the macro needs to kno
what VBE module is presently active / hi-lited. I know how to do mos VBE programming, just not how to know which module is active. How do do this? Thank -- Message posted from http://www.ExcelForum.com |
Active VBE Module ?
It depends on what you actually need. If you need the window,
use Application.VBE.ActiveWindow. If you need the code module object, use Application.VBE.ActiveCodePane.CodeModule -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "MWE " wrote in message ... I wish to execute a macro while in the VBE and the macro needs to know what VBE module is presently active / hi-lited. I know how to do most VBE programming, just not how to know which module is active. How do I do this? Thanks --- Message posted from http://www.ExcelForum.com/ |
Active VBE Module ?
Chip:
Thanks: what you provided was quite helpful. I was able to figure ou how to get the VBComponent Name associated with the active code modul (which is what I really wanted). (Application.VBE.ActiveCodePane.CodeModule.Parent. Name) I also need to go "up" another level (or two) and determine th worksheet name for the VBProject that contains the VBComponent with th active code module. Using something lik Application.VBE.ActiveVBProject does not work because as soon as my VB macro executes, the ActiveVBProject is reset from the active VBProjec in the VBE to the VBproject that contains the macro code (it is simila to the ActiveWorksheet vs ThisWorkSheet issue). Thank -- Message posted from http://www.ExcelForum.com |
Active VBE Module ?
MWE,
If you want to get the VBProject of a CodePane, use Set VBProj = VBCodePane.CodeModule.Parent.Collection.Parent To get the Workbook associated with the CodePane, you have to loop through the workbooks and compare file names. E.g., Dim WB As Workbook Dim VBProj As VBIDE.VBProject Dim VBComp As VBIDE.VBComponent Set VBProj = VBCodePane.CodeModule.Parent.Collection.Parent For Each WB In Application.Workbooks If WB.FullName = VBProj.Filename Then Exit For End If Next WB Debug.Print WB.FullName To get the worksheet associated with the CodePane, you have to loop through the worksheets and compare code names. (The following assumes that VBCodePane is set to the code pane of a sheet module.) Dim WS As Worksheet For Each WS In WB.Worksheets If WS.CodeName = VBCodePane.CodeModule.Parent.Name Then Exit For End If Next WS Debug.Print WS.Name -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "MWE " wrote in message ... Chip: Thanks: what you provided was quite helpful. I was able to figure out how to get the VBComponent Name associated with the active code module (which is what I really wanted). (Application.VBE.ActiveCodePane.CodeModule.Parent. Name) I also need to go "up" another level (or two) and determine the worksheet name for the VBProject that contains the VBComponent with the active code module. Using something like Application.VBE.ActiveVBProject does not work because as soon as my VBA macro executes, the ActiveVBProject is reset from the active VBProject in the VBE to the VBproject that contains the macro code (it is similar to the ActiveWorksheet vs ThisWorkSheet issue). Thanks --- Message posted from http://www.ExcelForum.com/ |
Active VBE Module ?
Chip: thanks (again); my question has been fully resolved.
MW -- Message posted from http://www.ExcelForum.com |
All times are GMT +1. The time now is 11:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com