Code to find code

  • Thread starter Thread starter D.
  • Start date Start date
D

D.

Hi,
What's the code to find a code?
I would like to be able to click a button and it will take me to a
particular code in the vba viewer
Thanks
 
Try something like the following.


Sub AAA()
Dim FindWhat As String
Dim StartLine As Long
Dim EndLine As Long
Dim StartCol As Long
Dim EndCol As Long
Dim Found As Boolean

With Application.VBE
If .ActiveCodePane Is Nothing Then
MsgBox "No Code Pane Active"
Exit Sub
End If
With .ActiveCodePane
FindWhat = "findme"
StartLine = 0
EndLine = .CodeModule.CountOfLines
StartCol = 0
EndCol = 0
Found = .CodeModule.Find( _
target:=FindWhat, _
StartLine:=StartLine, _
startcolumn:=StartCol, _
EndLine:=EndLine, _
endcolumn:=EndCol, _
wholeword:=False, _
MatchCase:=False, _
PatternSearch:=False)
If Found = True Then
.SetSelection StartLine, StartCol, EndLine, EndCol
Else
MsgBox "Not Found"
End If
End With
End With
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
Thanks Chip,
That seems like quite a long code,
Maybe I should have worded it differently

What's the code to go to a code, ,
I have seen sample workbooks, with a button, ie:Click here to view
code

Of course now that I want to use that type of code I can't find any of
those workbooks
 
Back
Top