Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Active VBE Module ?

Chip: thanks (again); my question has been fully resolved.

MW

--
Message posted from http://www.ExcelForum.com



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Row select mode to highlight active row of active cell Bart Fay[_2_] Excel Discussion (Misc queries) 0 May 11th 10 09:34 PM
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
HOW TO COPY 480 ACTIVE E-MAIL ADDRESSES CLM "G" ON AN ACTIVE EXCE. ragman10 Excel Discussion (Misc queries) 1 December 13th 04 11:52 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 09:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"