View Single Post
 
Old 08-12-2013, 10:07 AM
switchup621 switchup621 is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Aug 2013
Posts: 1
switchup621 is on a distinguished road
Default find and replace text Outlook VBA help

Hi everyone,

I am a relatively new to Office VBA although I have a ton of experience with visual studio. I am having some difficulty getting some rather simple code to work.

What i would like to do is when I open a draft with text already in it, I would like to run a macro that find text of my choosing and then replace that text with a different word of my choosing.

For example, if in my message I have in there somewhere the text [NAME], I could run a macro to find every instance of the text [NAME] and then replace with say "John."

So far I can't even make my code find a word in the message, I think I am missing code that says "search in this message" or at least "search highlighted text."

Here is what I have so far:

Code:
Sub test()
With Selection.Find
   .ClearFormatting
   .Highlight = True
   strFindText = InputBox("Enter the text you want to find.", _
      "Find Text")
   If Len(strFindText) = 0 Then Exit Sub
   .Text = strFindText
   If .Execute = True Then
      MsgBox "'" & Selection.Text & "'" _
         & " was found and is now highlighted."
   Else
      MsgBox "The text could not be located."
   End If
End With
End Sub
Any thoughts?
Reply With Quote