Excel VBA SendKeys "into" VBIDE - moving the Cursor within the modue

T

Travis McGee

Have values in a Worksheet Like this Cells 1-4
Module Name | Line No | Sub or Function | Name of the Proc (hundreds of
them)
Module2 135 Sub completeStrengthsForSwiss()
Module1 4117 Function convertDutchAsciToUnicode(ByVal sStr
As String) As String

By clicking on a button on the Worksheet, I want to go to the Module and the
Function.
I can get the code to Activate the Module (proboably Line #1), but going to
the Funcion with Cursor is the part I couldn't do.
I want to do Find
SendKeys is an Application Method, but when you use it against the VBIDE
..... it errors even if the "Module" is active at that time.
When you do Application Method, it works against the Worksheet.

Sub findSelectedFunction()
iRow = ActiveCell.Row
sModule = Cells(iRow, 1): sType = Cells(iRow, 3): sFunction = Cells(iRow, 4)
sFunction = Left(sFunction, InStr(sFunction, "(") - 1)
sName = sType & " " & sFunction
Set wb = ThisWorkbook: Set VBProj = wb.VBProject
VBProj.VBComponents(sModule).Activate .............this one works, it
actually Activates the Moduel that I want in Cell 1
VBProj.VBComponents(sModule).SendKeys("^F") <=========Error here. Find /
Control F
VBProj.VBComponents(sModule).SendKeys("Sub completeStrengthsForSwiss(")
VBProj.VBComponents(sModule).SendKeys("~N") ................. for FindNext
'Set oMod = VBProj.VBComponents(sModule).CodeModule
End Sub

Any other suggestions for moving the Cursor within the modue to a desired
text?
 
C

Cindy M.

Hi Travis,
Have values in a Worksheet Like this Cells 1-4

This group targets Word.VBA, not Excel. You should post in
the Excel.programming newsgroup for Excel questions.

That said, your question is not really application-
specific, but...

VBProj.VBComponents(sModule).SendKeys("^F")
<=========Error here

SendKeys cannot be used the way you're using it - you can't
"hang it onto" some other object. You'd need to remove
everything before SendKeys.

That said, I think the SetSelection method might be what
you're looking for:

ActiveDocument.VBProject.VBComponent( _
sModule).CodeModule.CodePane.SetSelection('parameters
follow

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top