Results 1 to 10 of 10

Thread: [RESOLVED] saving outlook mail item after sending it from vba

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Resolved [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
    Last edited by bambo; Jan 7th, 2006 at 11:58 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: saving outlook mail item after sending it from vba

    You can try to save the item when its being sent.
    VB Code:
    1. 'VBA Code
    2. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    3.     Item.Save 'Or something like that
    4. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    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?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    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.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    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?

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    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!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width