Outlook vba query

Soldato
Joined
26 Aug 2004
Posts
7,571
Location
London
Hi,

I'm trying to create a macro in outlook (2007) that, when clicked, loads up a form in which you can pick several options and enter some text. Once these are entered and a button is pressed the form should then load up an e-mail, which it populates with your choices.

I can make the form without problems and I have the following code create the e-mail:

PHP:
 Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    Set objMail = olApp.CreateItemFromTemplate("C:\xxxxxxx.oft")
    With objMail
        .BodyFormat = olFormatHTML
        .Subject = "Award Announcement"
        .To = "xxxxxxxxx"
        .Display
    End With

My problem is how to edit the contents of the e-mail to include, for example, the person's name. If this were MS Word I'd just do a find/replace, but for some reason Outlook doesn't have this function.

So, how do I replace text in an outlook e-mail without a find/replace function?

EDIT:
Typing all that out gave me an idea... I used Word's functions! The below works

PHP:
Dim wdSelection As Word.Selection
Dim wdDoc As Word.Document

Set wdDoc = Application.ActiveInspector.WordEditor
Set wdSelection = wdDoc.Windows(1).Selection

wdSelection.Find.ClearFormatting
wdSelection.Find.Replacement.ClearFormatting
With wdSelection.Find
.Text = "X1"
.Replacement.Text = "it worked"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdSelection.Find.Execute Replace:=wdReplaceAll

</thread>
 
Last edited:
Back
Top Bottom