I'm trying to create a macro that can compare the same macro from 2 different files, and get me the diferences, similar to a local GitHub but on a smaller scale.
Fist step is done, that is to get a TreeView with all Modules grouped by type, and on Node Click, load all macros in a listview, with Start row, End Row, row Count.
What I'm trying to do with the macro below is to give it a line and a module name as variables, and the code should bring the target module in the activecodepane and select the macro from first to last row.
Unfortunately it's not doing that, it's actually selecting the line in the form code. Can you guys point out what I'm missing?
Public Sub VBA_SelectMacro(lLine As Long, Optional moduleName As String)
'https://stackoverflow.com/questions/32381879/how-to-jump-to-line-number-in-vba-editor
Dim lActiveLine As Long
Dim sProc As String
Dim ProcType As Long
Dim vbaModule As CodeModule
Dim vbaPane As CodePane
Dim startLine As Long
Dim VBEProj As VBIDE.VBProject
Dim vbComp As VBIDE.VBComponent
Dim VBProj As VBIDE.VBProject
'On Error Resume Next
'lLine = Application.InputBox("Enter Line", "Go to Line", , , , , , 1)
If moduleName <> "" Then
'Set vbaPane = Application.VBE.CodePanes(moduleName)
Set VBProj = ActiveWorkbook.VBProject
Set vbComp = VBProj.VBComponents(moduleName)
Set vbaModule = vbComp.CodeModule
VBProj.VBComponents(moduleName).Activate
vbaPane.SetSelection lLine, 1, lLine + 1, 1 'if i take out the on error resume next, i get the error "91: Object variable or With block variable not set"
End If
Set vbaPane = Application.VBE.ActiveCodePane
Set vbaModule = vbaPane.CodeModule
If lLine > 0 Then
vbaPane.GetSelection lActiveLine, 0, 0, 0
sProc = vbaModule.ProcOfLine(lActiveLine, vbext_pk_Proc)
With vbaModule
startLine = .ProcStartLine(sProc, ProcType)
.CodePane.SetSelection startLine + lLine, 1, startLine + lLine + 1, 1
End With
End If
End Sub