SetFocus for control on built-in form

  • Thread starter Thread starter donchanger
  • Start date Start date
D

donchanger

Is there a way to set the focus to a control on a built-in form in VBA? I
have a macro attached to a button that does a simple substitution in my
signature, but it only works if the "body" of the message has the focus when
I click the button (I'm using SendKeys with a search and replace).

Since the form is "built-in", there is no ModifiedFormPages. Is there a way
to set the focus? Maybe even just a keyboard shortcut?

Thanks for any help or suggestions,

Don

Code Snip:

Sub SrchRepl(Srch, Repl)
'search the message body for the first occurrence of 'srch' and replace
with 'repl'
'need to set the focus in the body (control "message") on the form
SendKeys "{F4}"
SendKeys Srch
SendKeys "{ENTER}"
SendKeys "%{F4}", True
SendKeys Repl, True
End Sub
 
How about reworking your code completely and use the Replace function
against the MailItem.Body property? Then you don't have to worry about
control focus at all, and can do away with SendKeys entirely.

--
Eric Legault - MVP - Outlook
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, WSS 3
Application Development, MOSS 2007 Application Development)
Blog: http://blogs.officezealot.com/legault
Try Picture Attachments Wizard for Outlook!
http://www.collaborativeinnovations.ca
 
I thought about that first, but wasn't sure how to handle the various
permutations of BodyFormat (HTML, Plain, RTF). For HTML, I think you have to
use the HTMLBody property, and search/replace twice (because I am replaing an
email address in a signature, which ends up as both text and a "mailto"
link). For Plain, I would search once against the Body property. I have no
idea about RTF format (not sure if/when that would come into play).

In the past, when I tried something similar, the format of the body kept
changing (and dropping attachments sometimes, never could figure out
why/when), but this was using OLK2000.

Yours is a good thought and I guess I'll give that a try since I agree
SendKeys is clunky and I can't get the focus on the right control anyway.

Thanks,

Don
 
Back
Top