Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2013, 10:07 AM
switchup621 switchup621 is offline find and replace text Outlook VBA help Windows 7 64bit find and replace text Outlook VBA help Office 2010 32bit
Novice
find and replace text Outlook VBA help
 
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
  #2  
Old 08-13-2013, 10:05 AM
msperry msperry is offline find and replace text Outlook VBA help Windows 7 64bit find and replace text Outlook VBA help Office 2010 64bit
Competent Performer
 
Join Date: Jul 2011
Location: Jacksonville, Florida, US
Posts: 141
msperry is on a distinguished road
Default

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!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
find and replace text Outlook VBA help 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 text Outlook VBA help Find and replace a string of text errtu Word 1 01-31-2013 02:09 PM
find and replace text Outlook VBA help Insert text at the end of a sentence Find/Replace AlmostFriday Word 6 06-17-2012 05:21 AM
find and replace text Outlook VBA help 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft