[RESOLVED] saving outlook mail item after sending it from vba
Hey,
I'm using vba to send email with outlook.
the outlook item is previewed before sent, so that the user can add email recipents, body text and attachements to the original message.
I'd like to be able to save the mail item after it is sent from outlook with all the revisions that the user made to the original message (that was sent through the vba code).
problems are:
1. the users modifications are not saved to the file, just the original message that was sent from vba.
2. for trying to save the file to hdd, I get the securtiy message prompting the user to authorize the sending (must I build a trusted object for this)
here's the code:
Set outlookApp = CreateObject("Outlook.Application")
Set outlookMailItem = outlookApp.CreateItem(olMailItem)
With outlookMailItem
.To = strTo
.Subject = Nz(strSubject)
.Display
End With
strSubject = outlookMailItem.Subject
outlookMailItem.SaveAs SaveFile, 3
Re: saving outlook mail item after sending it from vba
You can try to save the item when its being sent.
VB Code:
'VBA Code
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Item.Save 'Or something like that
End Sub
Re: saving outlook mail item after sending it from vba
1. I tried adding outlookMailItem.Save after sending the email in the code and it didn't work- still only the original item was saved?
2. any ideas about the security issue?
Re: saving outlook mail item after sending it from vba
If your code is outside of Outlooks VBA then your going to need to convert it into an Outlook Trusted Add-In or use a third party control to dismiss the security prompt (not really recommended).
For the Save issue you can also try creating an Item_Add event for the Outbox MAPIFolder. This folder gets all sent email messages temporarily until the message is processed.
Re: saving outlook mail item after sending it from vba
my code is inside Access. do you any link on how to make my code a trusted object?
about the save issue: when do I move it to the outbox folder- if it's from the vba code then the user can't modify anything in it- because it is being sent while it is inside this folder.
Re: saving outlook mail item after sending it from vba
It gets moved to the Outbox automatically by Outlook. I think the code would reside in Outlooks VBA but it will save for all items being sent unless you have some criteria that can filtered. Also, Outlook would have to be running on the users system.
To make it trusted you need to use the VB "Add-In" project template and use the passed in Application object of the OnConnect procedure.
Re: saving outlook mail item after sending it from vba
saving the item- basically, is there any way you can think of doing this ?
I've built the adding project and created the addin dll, could you explain how to install it in another machine?
Re: saving outlook mail item after sending it from vba
Its just a matter if copying over the created .dll file as long as there is no other dependancies. Then go into tools > options > other > advanced options > com add-ins button > browse to your dll location > select it > click Ok.
Re: saving outlook mail item after sending it from vba
This thread may aslo give you more help/ideas.
http://www.vbforums.com/showthread.php?t=346767
Re: saving outlook mail item after sending it from vba
thanks for all the help. I finally waited upon an item add into sent item folder and then acted upon it.
thanks again!!!