Email from template

burrelly

Registered User.
Local time
Today, 10:59
Joined
Sep 5, 2008
Messages
79
I am trying to create an email from an oft templaye and replace certain part using the replace() function. I can get the email to open up but not of the replaces are working.

Can anyone off any help?

Code:
    [FONT=&quot]Dim myOlApp As Outlook.Application[/FONT]
  [FONT=&quot]Dim MyItem As Outlook.MailItem[/FONT]
  [FONT=&quot]Dim objDoc As Object[/FONT]
  [FONT=&quot]Dim OutlookRecip As String[/FONT]
  [FONT=&quot]Dim strCustomer As String[/FONT]
  [FONT=&quot]Dim strHTML As String[/FONT]
  [FONT=&quot] [/FONT]
  [FONT=&quot] [/FONT]
  [FONT=&quot]Set myOlApp = CreateObject("Outlook.Application")[/FONT]
  [FONT=&quot]Set MyItem =[/FONT]
  [FONT=&quot]myOlApp.CreateItemFromTemplate("C:\template.oft")[/FONT]
  [FONT=&quot]strCustomer = "Simon"[/FONT]
  [FONT=&quot]strHTML = Replace(MyItem.HTMLBody,"%subfirstname%", strCustomer)[/FONT]
  [FONT=&quot]MyItem.Display[/FONT]
  [FONT=&quot]Set objDoc = MyItem.GetInspector.WordEditor[/FONT]
  [FONT=&quot]objDoc.Windows(1).Selection.Find.ClearFormatting[/FONT]
  [FONT=&quot]objDoc.Windows(1).Selection.Find.Execute strSender[/FONT]
  [FONT=&quot]Set myOlApp = Nothing[/FONT]
  [FONT=&quot]Set MyItem = Nothing[/FONT]
  [FONT=&quot]Set objDoc = Nothing[/FONT]
 
What does it mean that Replace() is not working? Do you get an error? Do you get an incorrect result?
Describing the problem in greater detail improves your chance of getting detailed assistance. To say a thing 'doesn't work' is not enough.
Cheers,
 
Out look opens the oft template but does not replace the placeholder text at all. No errors or anything like that.
 
Set MyItem =
myOlApp.CreateItemFromTemplate("C:\template.oft")
strCustomer = "Simon"
strHTML = Replace(MyItem.HTMLBody,"%subfirstname%", strCustomer)

I think the issue is that MyItem is being interpreted as a template file not the actual contents of the file. What happens if you pass the HTMLBody to a string variable and do a replace on that. Try doing a debug.print MyItem.HTMLBody and HTMLBody only to see what appears.
 
I think the issue is that MyItem is being interpreted as a template file not the actual contents of the file. What happens if you pass the HTMLBody to a string variable and do a replace on that.

Could you explain how to do that?
 
Ok try this

strHTML = MyItem.HTMLBody

Debug.Print strHTML
 

Users who are viewing this thread

Back
Top Bottom