Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA code to insert text into a fetched template.

Status
Not open for further replies.

Mollethewizard

IS-IT--Management
Nov 18, 2002
93
0
0
SE
Is it possible to put some text at the top of the body in a fetched template via VBA code?

The main body of the template is sent to different users with a text at the top of the body that differs (a text string that have a number of variables from textboxes in the user form. I hope that you understand what i am trying to achieve.

Sub Win7medarb()
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate("K:\Outlook\Nymedarb.oft")

With frmWin7medarb
.Show
End With


With MyItem
.To = frmREXxp.txtRecipient
End With

MyItem.display

frmREXxp.txtRecipient = ""
Set MyItem = Nothing
Set myOlApp = Nothing

End Sub
 
Mintjulep thanks for your answer – but the templates body already has a text and what I want is to insert text into it. Your suggestion erases the text in the body and replaces it with – Whatever :)
 
And this ?
MyItem.Body = "Whatever" & vbCrLf & MyItem.Body

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Works but the embedded images in the original body are lost.
 
So, you have to play with the HTMLbody.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes - and I have found some code at the internet (the lifeline besides Tek-Tips :)) hope that I can modify it for my purpose. Have a nice weekend.
 
Your suggestion erases the text in the body and replaces it with – Whatever :)


Well yes, it would do that.

But tell me. How could I have known from your original post that there was already text in the body?

And they PVH offered a suggestion to address that, and then we learned that there are pictures too.

If those two pieces of information were given in your original post it would have helped you get your answer faster.
 
I humbly apologize that I was not specific in my original post.
And I can’t get my code to work either.
In the template there is %user% embedded in the text and that text I want to replace and if it work a pieces of other text too.
I’ve used this code and the template pops up in Outlook but the %user”% remains.

Sub Win7medarb()

Dim strHTML As String
Dim rep1 As String

Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate("K:\Outlook\Nymedred.oft")

rep1 = "Mr Bean"

strHTML = Replace(MyItem.htmlBody, "%user%", rep1)

With MyItem

.htmlBody = strHTML

End With

MyItem.display

Set MyItem = Nothing
Set myOlApp = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top