J
John
I’ve run into some strange behavior programming Outlook to send an
email message. Specifically, this relates to Outlook 2002 using Word
2002 as the default email editor. I can send a message as follows,
assuming that an instance of Outlook is running:
Private Sub Send()
Dim olkApp As Outlook.Application
Dim olkMailItem As Outlook.MailItem
Set olkApp = Outlook.Application
Set olkMailItem = olkApp.CreateItem(olMailItem)
With olkMailItem
.Recipients.Add “some name”
.Subject = “Some Subject”
.Body = “Body.”
.Send
End With
End Sub
When a user later closes Outlook, Word prompts the user to save “Some
Subject”. Certainly, this doesn’t happen when a message is sent
manually. Is there anything about the way the message is being sent by
the code above that would account for this?
To work around this behavior, I’ve done the following:
Private Sub SendHack()
Dim olkApp As Outlook.Application
Dim olkMailItem As Outlook.MailItem
Dim olkInspector As Outlook.Inspector
Dim wrdDoc As Word.Document
Set olkApp = Outlook.Application
Set olkMailItem = olkApp.CreateItem(olMailItem)
With olkMailItem
.Recipients.Add “some name”
.Subject = “Some Subject”
.Body = “Body.”
End With
Set olkInspector = olkApp.Inspectors.Add(olkMailItem)
Set wrdDoc = olkInspector.WordEditor
wrdDoc.Save
olkMailItem.Send
End Sub
Is there a better way to accomplish the same end, that of not having
the user prompted to save or not save a Word document for apparently
no reason?
Thanks.
email message. Specifically, this relates to Outlook 2002 using Word
2002 as the default email editor. I can send a message as follows,
assuming that an instance of Outlook is running:
Private Sub Send()
Dim olkApp As Outlook.Application
Dim olkMailItem As Outlook.MailItem
Set olkApp = Outlook.Application
Set olkMailItem = olkApp.CreateItem(olMailItem)
With olkMailItem
.Recipients.Add “some name”
.Subject = “Some Subject”
.Body = “Body.”
.Send
End With
End Sub
When a user later closes Outlook, Word prompts the user to save “Some
Subject”. Certainly, this doesn’t happen when a message is sent
manually. Is there anything about the way the message is being sent by
the code above that would account for this?
To work around this behavior, I’ve done the following:
Private Sub SendHack()
Dim olkApp As Outlook.Application
Dim olkMailItem As Outlook.MailItem
Dim olkInspector As Outlook.Inspector
Dim wrdDoc As Word.Document
Set olkApp = Outlook.Application
Set olkMailItem = olkApp.CreateItem(olMailItem)
With olkMailItem
.Recipients.Add “some name”
.Subject = “Some Subject”
.Body = “Body.”
End With
Set olkInspector = olkApp.Inspectors.Add(olkMailItem)
Set wrdDoc = olkInspector.WordEditor
wrdDoc.Save
olkMailItem.Send
End Sub
Is there a better way to accomplish the same end, that of not having
the user prompted to save or not save a Word document for apparently
no reason?
Thanks.