On Closing Outlook after Programmatically Sending Email, Word Promptsto Save

  • Thread starter Thread starter John
  • Start date Start date
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.
 
See if saving the mail item before sending it gets rid of that prompt from
Word.




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.
 
I'd tried the Save method of the Outlook.MailItem object but found
that it did not prevent the prompt from Word. (Tried it again just now
to confirm.) Thanks.
 
If that doesn't work then I'd stick with the workaround you already found.




I'd tried the Save method of the Outlook.MailItem object but found
that it did not prevent the prompt from Word. (Tried it again just now
to confirm.) Thanks.
 
Back
Top