Is there only ever going to be one code module? It could be quite restrictive if there were only to be one. Is it always going to have the name Module 1? The recording of a macro will frequently create a new one. I can certainly get the vbe to open at the top of module 1:
Code:
Dim VBAEditor As VBIDE.VBE
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Set VBAEditor = Application.VBE
Set VBProj = VBAEditor.ActiveVBProject
Set VBComp = VBProj.VBComponents("Module1")
Set CodeMod = VBComp.CodeModule
VBAEditor.MainWindow.Visible = True
CodeMod.CodePane.Show
LineNum = 1
If Not Intersect(ActiveCell, ActiveSheet.Range("AM23:AM36").SpecialCells(2)) Is Nothing Then LineNum = CodeMod.ProcStartLine(ActiveCell.Value, vbext_pk_Proc)
CodeMod.CodePane.TopLine = LineNum
CodeMod.CodePane.SetSelection LineNum, 1, LineNum, 1
As an aside, I note that the code which populates that section of the sheet has the line:
Code:
Rng(1, 2).Value = ProcKindString(ProcKind)
which tries to put the likes of "Sub or Function" in the cell immediately to the right of where the procedure name is placed, but because the cells are merged nothing gets put there. If you were to unmerge some cells in that vicinity that data could become visible/available, furthermore, you could have an additional cell in the row which contains the name of the module that that procedure is in, for example:
Code:
Rng(1, 8).Value = .Name
which you could later use, either in a loop to run through the code modules, or to allow the single module to have any name by changing the line:
Code:
Set VBComp = VBProj.VBComponents("Module1")
to:
Code:
Set VBComp = VBProj.VBComponents(ActiveCell(, 8).Value)
Bookmarks