Get Document Name from VB Project
I have a macro that iterates through all VB projects' code modules to gather information about them. The loops look like the following:
For k = 1 To Application.VBE.VBProjects.Count ' 1st one is Normal then documents
Set VBProj = Application.VBE.VBProjects(k)
If VBProj.Protection = vbext_pp_none Then ' Process code modules only
For j = 1 To VBProj.VBComponents.Count ' Iterate thru components
Set VBComp = VBProj.VBComponents(j)
Set CodeMod = VBComp.CodeModule ' Process Code Module
with CodeMod
.
.
end with
The only way I could return the name of the document (or Template in the case of Normal which is always the first VB project) that each CodeMod belongs to was from the code pane's window's caption:
sFilename = Left(.CodePane.Window.Caption, InStr(CodeMod.CodePane.Window.Caption, "-") - 2)
This worked fine in Word 2011. But I've been forced to upgrade to 2019 and the system reports an error with CodeMod.CodePane.Window.Caption now (see attachment).
Can anyone tell me how to go about getting the name of the document from the VB project or it's components/modules? All help is much appreciated!
Last edited by VBorNotVB; 11-02-2018 at 07:15 AM.
Reason: Title Ambiguous
|