Mail merge to word template stored in outlook folder?

J

JeffArcherJr

Can anyone tell me how to do a mailmerge to a word template stored in a
outlook folder on my exchange server.

The template is stored at: Outlook://Mailbox - MyCompany/Forms

"Forms" is a Task List (though it could be another outlook folder typ
if that made things easier. Inside "Forms" is a task subject "Test"
and in "Test" is a word template "Test.Dot"

Using the code below (borrowed from Ken Slovaks "Programming outlooo
2002"). Works fine so long as the word document is on my C: drive, bu
I can't work out how to point to it programatically when it is in a
outlook folder?

Thanks

Jeff

Public Sub MailMerge()
'mail merge contact data to a word document
On Error GoTo MailMergeError

Dim FilePath As String
Dim appOL As Outlook.Application
Dim appWord As Word.Application
Dim docDocs As Word.Documents
Dim insInspector As Inspector
Dim itmContact As ContactItem
Dim strAddress As String
Dim strPath As String
Dim objCustProperties As Object
Dim objTmp As Object


Set appOL = CreateObject("Outlook.Application")
Set insInspector = appOL.ActiveInspector
Set objTmp = insInspector.CurrentItem


'check that we have a contact selected before we do the mail merge
If objTmp.Class = olContact And objTmp.MessageClass = "IPM.Contact
Then
Set itmContact = objTmp
Else
MsgBox "Need to select a contact to do the mail merge with!"
Exit Sub
End If

'open up word document
Set appWord = CreateObject("Word.Application")

'strPath = "\\Mailbox - MyCompany\Forms\Test\~Test.dot" ' faile
test!

strPath = "c:\test.dot"
Set docDocs = appWord.Documents
docDocs.Add strPath
appWord.Visible = True

'fill and merge
Set objCustProperties = appWord.ActiveDocument.Fields
objCustProperties.Item("AddressName") = "Test One"
objCustProperties.Item("No") = "Test"
appWord.ActiveDocument.Fields.Update
appWord.Activate
appWord.Selection.WholeStory
appWord.Selection.EndKey Unit:=wdStory, Extend:=wdMove

Exit Sub

MailMergeError:
MsgBox "Went to Error"
'appWord.ActiveDocument.Close (wdDoNotSaveChanges)
'appWord.Quit

End Su
 
S

Sue Mosher [MVP]

You would first have the save the template as a file to your C:\ drive or
some other volume using the Attachments.SaveAsFile method. (That's
essentially what Outlook does when you open the template from the public
folder.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top