SendKeys using Find dialog box...

J

JonathanSLim

Hi,

I've been racking my brain for 2 days trying to get this to work using
simple SendKeys command.

My goal is to find text like "mytext" using the Find menu command and
then exit it, leaving the "mytext" selected.

It does everything but exits the dialog box. I've tried sending {TAB
3}, {ENTER}, and {%F} but nothing works. If I try the same keystroke
using my keyboard, no problem.

Please help.

Sample Code:

Sub CLIbox_emphasis()
'send ALT-E-F as if pressing the keys on the keyboard
SendKeys "%EF", True

'send "mytext" and put it in the "Find What: " search field of the
dialog
SendKeys "mytext", True

' ******* the next line is where it does not respond ******
SendKeys "{ENTER}", True

' close the Find dialog box but but doesn't find "mytext"
SendKeys "{ESC}", True
End Sub


Thanks in advance...
 
J

JonathanSLim

Try:

SendKeys "%EF", True
SendKeys "mytext", True
SendKeys "+{TAB 2}", True
SendKeys "{ENTER}", True

--
Regards,
Shyam Pillai

Animation Carbonhttp://www.animationcarbon.com


Hi Shyam,

Thanks for responding so quickly. I've tried that and I get the same
result. My cursor doesn't move anywhere near the words "mytext" and
nothing is highlighted. I'm using PowerPoint 2003 with SP2. I read
somewhere there was a bug with the Find feature in PowerPoint? Could
this be affecting it?

Or maybe my approach is wrong? This piece of code is a part 2 of 3 that
I wanted to call when formatting some text. I am a technical courseware
developer and our software is CLI based... like the DOS command prompt.
I frequently copy text from our software and paste it into a text box
on a slide for use as examples.

I've been successful with Part 1 and Part 3. Part 2 (the find and
highlight part) is the glue that I'm missing.

The end result is a macro called CLI_FRAME () that runs PART 1, 2, and
3 sequentially.

If you could help me with this I'm sure lots of other people may find
it useful and would make a great example in the book.

---------------- For PART 1 -----------------
I have been able to successfully format the text box. It adds a border,
sets the basic font, line spacing, paragraph alignments, etc. This is
done, after I click anywhere in the text box and run the macro CLI_box
() as follows:

******************************************
Sub CLI_box()
'
' Formats entire frame to a default font, spacing, color, & line border
'
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
With ActiveWindow.Selection.TextRange.Font
.NameAscii = "Courier New"
.NameOther = "Courier New"
.Size = 12
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.RGB = RGB(Red:=206, Green:=206, Blue:=206)
End With

With ActiveWindow.Selection.TextRange.ParagraphFormat
.Bullet.Visible = msoFalse
.LineRuleWithin = msoTrue
.SpaceWithin = 1#
.LineRuleBefore = msoFalse
.SpaceBefore = 0#
.LineRuleAfter = msoFalse
.SpaceAfter = 0
End With

With ActiveWindow.Selection.ShapeRange
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(0, 35, 45)
.Fill.Transparency = 0#
.Line.Weight = 4
.Line.Style = msoLineThinThin
.Line.Visible = msoTrue
.Line.ForeColor.SchemeColor = ppAccent3
.Line.BackColor.RGB = RGB(255, 255, 255)
.TextFrame.MarginLeft = 3.6
.TextFrame.MarginRight = 3.6
.TextFrame.MarginTop = 3.6
.TextFrame.MarginBottom = 3.6
.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft
.TextFrame.HorizontalAnchor = msoAnchorNone
.TextFrame.VerticalAnchor = msoAnchorTop
End With

ActiveWindow.Selection.ShapeRange.ZOrder msoBringToFront
ActiveWindow.BlackAndWhite = msoTrue
ActiveWindow.Selection.ShapeRange.BlackWhiteMode =
msoBlackWhiteAutomatic
ActiveWindow.BlackAndWhite = msoFalse
ActiveWindow.View.ZoomToFit = msoTrue
ActiveWindow.Selection.ShapeRange.AutoShapeType = msoShapeRectangle
ActiveWindow.Selection.ShapeRange.TextFrame.AutoSize =
ppAutoSizeMixed

End Sub
******************************************

---------------- For PART 3 -----------------
I have been able to successfully format the line of text into two parts

For example:

TEXT-A = "CompanyX_prompt"
TEXT-B = "command"

So it would look like: CompanyX_prompt#command

Part A ("CompanyX_prompt)) is formatted in courier font not bolded
Part B (the command line to type in) is formatted in courier font
BOLD

This is done by clicking in between TEXT-A and TEXT-B and running the
following 3-part macros (PromptFont, CommandFont, and CLI_bullet)

******************************************
Sub CLI_Bullet()
'
' Insert cursor between the prompt symbol (> or #) and the start of the
command to format Blue
' This also adds a space after the prompt and bolds the command portion
'

' to select prompt text
SendKeys "+{HOME}", True
PromptFont
ActiveWindow.Selection.TextRange.Font.Italic = False
' to add a space after #
ActiveWindow.Selection.TextRange.InsertAfter " "
SendKeys "{RIGHT}", True
' to select command text
SendKeys "+{END}", True
CommandFont
ActiveWindow.Selection.TextRange.Font.Italic = False
ActiveWindow.Selection.Unselect
End Sub

Sub PromptFont()
' This changes the selected font to Blue (not Bold) for the CLI
prompt
ActiveWindow.Selection.TextRange.ParagraphFormat.Bullet = msoFalse
ActiveWindow.Selection.TextRange.ParagraphFormat.Alignment =
ppAlignLeft
With ActiveWindow.Selection.TextRange.Font
.NameAscii = "Courier New"
.NameOther = "Courier New"
.Size = 12
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.RGB = RGB(Red:=0, Green:=102, Blue:=153)
End With
End Sub

Sub CommandFont()
' This changes the selected font to Blue (Bold) for quoting a CLI
command after the prompt
With ActiveWindow.Selection.TextRange.Font
.NameAscii = "Courier New"
.NameOther = "Courier New"
' .Size = 12
.Bold = msoTrue
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.RGB = RGB(Red:=0, Green:=100, Blue:=150)
End With

End Sub

******************************************

---------------- Now for PART 2 -----------------

Now, I could've stopped there and just click on each line manually
after the "#" and run CLI_bullet manually each time, but since I was on
a roll with the macros, I thought I could go one step further and look
at each individual line in the macro using a dialog box.

This is done, after I click anywhere in the text box and run the macro
AskLine ()


******************************************
Sub AskLine()
Dim Msg, Style, Title, Response, MyString
' to define message:
Msg = "Do you want to bold the command on this line?"
' to define buttons:
Style = vbYesNoCancel + vbQuestion + vbDefaultButton1
' to define title:
Title = "Bolding Text in a CLI Box"
' to display message:
Response = MsgBox(Msg, Style, Title)
'If user chose Yes, then search for # and format using CLI_bullet
macro
If Response = vbYes Then
'open Find Text dialog box
SendKeys "%EF", True
'insert "#" for Find What text in dialog box
SendKeys "#", True
SendKeys "+{TAB 2}", True
SendKeys "{ENTER}", True
CLI_bullet
'move cursor down to beginning of next line and prep to find next #
character by running AskLine () macro again:
SendKeys "{DOWN}", True
SendKeys "{HOME}", True
' Run this again
AskLine

' User choses No, so don't find # but don't run AskLine () macro.
Instead just move cursor down one line.
ElseIf Response = vbNo Then
'move cursor down to beginning of next line and prep to find next #
character:
SendKeys "{DOWN}", True
SendKeys "{HOME}", True
' Run this again
AskLine
Else 'user chose Cancel
End If
End Sub

******************************************

Sub CLI_FRAME ()
'
' to use, click anywhere in the text frame and run this macro
'
'

' Format text box to CLI style
CLI_box

' move cursor to top left of text frame
SendKeys "^{HOME}", True

' process all lines
AskLine

End Sub



******************************************


Well, that's it. I tried to input notes to help follow the flow.
Hopefully it makes sense... Again, the bottleneck is when I try to
find the # character.

Thanks!
Jonathan
 

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