
Retrieve name of current sub/function and name of current module
Sorry but I saw the word Workgroups distinctly but it makes no difference as
the VB extensions required are the same. Anyway I never view other
newsgroups so that would account for my error. As for the collections not
starting at 0 that's news to me. I'll keep it in mind. But looking again I
notice that these are all Word collections, not VB collections so that makes
a bit of a difference.
As for the registry I meant that you would use it as a sort of one-line log
but looking at the problem a .txt file might be a better answer with exit
printing routines also.
Quote:
>>Given that
> you
> > are using Excel a routine shouldn't be that difficult to fathom out to
> > automatically add a few lines of code to each sub and function that
> doesn't
> > already have them.
Now to explain this. I was once shown a piece of code from a macro virus. It
was only for spreading it but it had a line something like:
print #1,vbcurrentproject.currentmodule.code.line(x) 'excuse the bad
call, it was at least 6 months ago
Using this you could add in lines to handle this, analysing the sub/function
name and then using it to add 3 lines(open,print,close) to the start and
end.
Hopefully this helps a bit more
BTBB
Quote:
> The registry idea "sounds" like a big performance hit to me.
> Cheers,
> Randy
> > Just two {*filter*}s on the BTBB's reply below:
> > First: We're doing Word here not Excel or atleast that's what I thought
> > since I caught the post in the word97vba newsgroup.
> > Second: Yep, I know that normally things in a collection start with 0,
> > however, not always and not in this case. The first thing I tried was
the
> > following simple line of code:
> > MsgBox VBProject.VBComponents(0).Name
> > and I got back the following error message:
> > Runtime Error 9: Subscript out of Range
> > and sometimes:
> > Runtime Error 5941: The requested member of the collection does not
> > exist.
> > I also built a loop exactly as is illustrated by BTBB below and got the
same
> > error until I fixed it to the way it was in my original post.
> > Another couple of instances I can specifically think of when a
collection
> > does not start at 0 are:
> > * Paragraphs
> > * BuiltInDocumentProperties
> > * Documents
> > * Sentences
> > But the idea about the Registry is very sound.
> > > First a simple rule in VB: .count for collections always start at 0 so
the
> > > line should have read
> > > For i = 0 To VBProject.VBComponents.Count-1
> > > Secondly as a possible solution couldn't you get each sub and function
to
> > > use the registry or similar to say what it is when it starts? Given
that
> > you
> > > are using Excel a routine shouldn't be that difficult to fathom out to
> > > automatically add a few lines of code to each sub and function that
> > doesn't
> > > already have them. Also if I remember correctly there is a Calls box
in
> > > Excel which could do what you ask if this is for debugging purposes.
> > > Hope this helps
> > > BTBB
> > > > I can give you one clue. Each in a VB project becomes part of the
> > > > VBProject collection.
> > > > You can get the name of each module in your VBProject by looping
through
> > > > the components and getting the Name property for each
> > component.Something
> > > > like this:
> > > > Sub printman()
> > > > For i = 1 To VBProject.VBComponents.Count
> > > > MsgBox VBProject.VBComponents(i).Name
> > > > Next i
> > > > End Sub
> > > > Now, I have no idea how you can use this to get the name of the
> > currently
> > > > active module or the currently running sub/function, but I think
this
> > > > would be better than using the VBE object.
> > > > > Hi all,
> > > > > I would like to write some code to retrieve the name of the
current
> > > module
> > > > > and the name of the current sub or function. For example, if I
have a
> > > module
> > > > > called modTest and a function called blnTest, then I would like to
get
> > > those
> > > > > names.
> > > > > Function blnTest as boolean()
> > > > > Debug.Print <name of current module>
> > > > > Debug.Print <name of current sub/function>
> > > > > End Function
> > > > > I really don't know where to look... I tried
> > > > > Workbooks("test.xls").VBProject.Name, but that gives me only the
name
> > of
> > > the
> > > > > project. I also tried
Application.VBE.ActiveCodePane.CodeModule.Name,
Quote:
> > > but
> > > > > that gives me the name of the CodeModule that is currently on top
of
> > the
> > > > > vb-editor. And that is not allways the module containing the
current
> > sub
> > > or
> > > > > function!
> > > > > Does anybody have a clue? thanx in advance!!!
> > > > > Marga.
> > > > > http://www.*-*-*.com/ ~in004323