View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default VBE code pane

Quartz,

VBA code is stored in the CodeModule of a VBComponent. A CodePane
is the visible representation of the CodeModule. A CodePane is
one of many types of a Window. Other Windows include the main VBE
window itself, the project explorer, the immediate window, etc.


2. If I have code stored in a sheet module, how can I get a

reference to the code pane that that sheet module is in?

To access the CodePane of a worksheet's code, use something like
the following:

Dim VBComp As VBIDE.VBComponent
Dim VBCodeMod As VBIDE.CodeModule
Dim VBCodePane As VBIDE.CodePane

Set VBComp = ThisWorkbook.VBProject.VBComponents( _
Worksheets("Sheet1").CodeName)
Set VBCodeMod = VBComp.CodeModule
Set VBCodePane = VBCodeMod.CodePane
Debug.Print VBCodePane.CountOfVisibleLines

3. How can you determine or equate the code pane object to any

other object in the VBE using VBA?

I'm not entirely sure what you are asking here, but you can get
to the VBComponent of a CodePane with code like the following:

Set VBComp = VBCodePane.CodeModule.Parent

To get to the VBProject containing a given CodePane, use

Dim VBProj As VBIDE.VBProject
Set VBProj = VBCodePane.CodeModule.Parent.Collection.Parent

For more information, see www.cpearson.com/excel/vbe.htm and
www.cpearson.com/excel/codemods.htm



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"quartz" wrote in message
...
Hello. I'm hoping an MVP or someone who knows can help me here.

1. Can someone please explain to me what a "CodePane" is and

how it differs from a "CodeModule" or, for that
matter, a window?

2. If I have code stored in a sheet module, how can I get a

reference to the code pane that that sheet module is in?

3. How can you determine or equate the code pane object to any

other object in the VBE using VBA?

4. Your example code regarding 2 & 3 above would be most

appreciated.

Thanks in advance for your assistance.