asked on
Dim wrdDoc As Word.Document
Dim olkApp As Outlook.Application
Dim olkMsg As Outlook.MailItem
Dim oDoc As String
'objFSO As FileSystemObject
'objFile As TextStream
Set wrdDoc = ActiveDocument
'Save the document in the proper format. If the document is already saved in the proper format,
'then you could change the command from SaveAs to Save.
wrdDoc.SaveAs , wdFormatFilteredHTML
'Read the document in using the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(wrdDoc.Path & "\" & wrdDoc.Name, 1, False)
'Get the open instance of Outlook
Set olkApp = GetObject(, "Outlook.Application")
'Create a new message
Set olkMsg = olkApp.CreateItem(0)
'Add recipients
olkMsg.Recipients.Add sEmail
'Add the subjec line
olkMsg.Subject = sMyCaseName & " Case Closure"
'Read the saved Word doc into the body of the message
olkMsg.HTMLBody = objFile.ReadAll
oDoc = (wrdDoc.Path & "\" & wrdDoc.Name)
'Close the Word Document
ActiveDocument.Saved = True
ActiveDocument.Close
'Destroy all the objects to avoid memory leaks
Set wrdDoc = Nothing
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
'Delete the saved form
Kill oDoc
'Display the message
olkMsg.Display
Set olkApp = Nothing
Set olkMsg = Nothing
Unload Me
Microsoft Outlook is a personal information manager from Microsoft, available as a part of the Microsoft Office suite. Although often used mainly as an email application, it also includes a calendar, task manager, contact manager, note-taker, journal, and web browser.
TRUSTED BY
That looks like code I wrote.
"When the document template is closed and the macro is run, the code fails."
The code is designed to work from the active document in Word. I guess I don't understand what it is you're trying to do.