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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Template File

Status
Not open for further replies.

TheVillageIdiot27

Programmer
Nov 10, 2005
58
GB
I am trying to create an Outlook Macro which can take the HTML body from a saved OFT message template and insert it into an open message being drafted.

At the moment I have nothing apart from the file path as a string and don't really know where to start.

I appreciate that this way of using a message template is quite clumsy but I am constrained by other factors.

Any help gratefully appreciated.
 
Here is a variation on what you are asking for. Instead of storing the HTML as an [tt]*.oft[/tt] file I saved it as a [tt]*.txt[/tt] file named C:\oft.txt. It includes the text that will be inserted into the message INCLUDING the relevent HTML tags.

Here is the Outlook routine:
Code:
Option Explicit

[navy]Public Sub [/navy] CrateNewHTML()
Const [navy]Error[/navy]Msg = "There is currently no draft message [navy]To[/navy] update!"
[navy]Dim[/navy] objMail [navy]As Object[/navy]
[navy]Dim[/navy] lngFile [navy]As Long[/navy]
[navy]Dim[/navy] strHTML [navy]As String[/navy]

[green]'Open the text file with the HTML and get the text[/green]
lngFile = FreeFile
Open "C:\oft.txt" [navy]For[/navy] Input [navy]As[/navy] #lngFile
strHTML = Input(LOF(lngFile), #lngFile)
Close #lngFile

[green]'Get the currently open Inspector[/green]
Set objMail = ActiveInspector.CurrentItem

[green]'Test the item returned[/green]
[navy]If[/navy] TypeName(objMail) = "Nothing" [navy]Then[/navy]
  [green]'No active Inspector open[/green]
  MsgBox ErrorMsg, vbOKOnly, "Append HTML Error"
  [navy]Exit Sub [/navy]
lse[navy]If[/navy] objMail.Class <> olMail [navy]Then[/navy]  [green]'olMail=43[/green]
  [green]'Active Inspector is not a mail item[/green]
  MsgBox ErrorMsg, vbOKOnly, "Append HTML Error"
  [navy]Exit Sub [/navy]
[navy]End If[/navy]

[green]'Write some data To the message[/green]
With objMail
  .Subject = "HTML Test"
  .HTMLBody = strHTML
[navy]End[/navy] With
[navy]End Sub [/navy]

And here are the contents of C:\oft.txt:
[tt] This is a test of inserting an
HTML tagged document into a an email draft.<p>
<b>This should be bold text</b><br>
<i>This should be italic</i>[/tt]

Hope this helps,
CMP

I am sorry I have not succeeded in answering all of your questions.
In fact, I apologize for not completely answering any of them.
The answers I have however do serve to raise a whole new set of questions I had not previously thought of. In some ways, I am as confused as you are but I believe my confusions are (as always) on a higher plane and
 
It's okay I have managed to sort this.

I used the create email from template method then copied the to,cc,bcc and HTMLbody properties the existing draft. I managed to get the attachments accross by saving them, then attaching them from that location.

The only problem I have is that the HTML image references in the mail created from the OFT template don't match the attachment names so the references don't work when copied across. To get round this I have stripped out anything in img tags but it doesn't really seem ideal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top