Unless you program (hard code) the information you want, such information is
not available in relation to an error to the best of my knowledge. (If you
hard code a significant key part of the chain of information you want, then
you can get the rest as Chip has shown).
Use of the components of the VBE object model do not require a reference to
the VBE extensibility. They will be late bound. However, if you declare
them as
Dim vbcomp as VbComponent
then you would need the reference since this is early binding.
--
Regards,
Tom Ogilvy
"Mark Worthington" wrote in message
om...
Chip et al,
I have devoured the great info on your site and elsewhere, but cannot
work out how to "easily" determine a standard module name in VBA. It
would appear NOT to be simply available via the VBComponents
collection etc, but I did come across your method, ref
Application.VBE.ActiveCodePane.CodeModule.Parent.N ame. This seems not
to require a reference in VBA to the VBA Extensibility library ....
With regard to the original question no. 3 :
3. How can you determine or equate the code pane object to any other
object in the VBE using VBA?
I would like to be able to determine the procedure, module & project
names so that my standard error handler can say "Error 1004 .... in
Procedure x, Module y, Project z." So I would like to ask if anyone
can enlighten me on determining the above names.
Many thanks,
Mark
"Chip Pearson" wrote in message
...
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.