![]() |
|
#1
|
|||
|
|||
|
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
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro to find text and replace with form field containing that text
|
iiiiifffff | Word VBA | 16 | 06-04-2016 01:47 AM |
Find and replace a string of text
|
errtu | Word | 1 | 01-31-2013 02:09 PM |
Insert text at the end of a sentence Find/Replace
|
AlmostFriday | Word | 6 | 06-17-2012 05:21 AM |
Bad view when using Find and Find & Replace - Word places found string on top line
|
paulkaye | Word | 4 | 12-06-2011 11:05 PM |
| Find and replace page numbers in body of text | tollanarama | Word | 3 | 02-13-2011 06:00 AM |