![]() |
#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 |
#2
|
|||
|
|||
![]()
Hi,
I think you'll find one of these two bits of code useful: http://www.outlookcode.com/threads.a...essageid=25743 http://www.outlookcode.com/threads.a...essageid=31845 Have fun! |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
iiiiifffff | Word VBA | 16 | 06-04-2016 01:47 AM |
![]() |
errtu | Word | 1 | 01-31-2013 02:09 PM |
![]() |
AlmostFriday | Word | 6 | 06-17-2012 05:21 AM |
![]() |
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 |