Results 1 to 9 of 9

Thread: Emailing results from XL automatically

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    8

    Emailing results from XL automatically

    Hi everyone,

    Following on from si the geek's post on automating excel (http://www.vbforums.com/showthread.php?t=391665), I would really like to hear from anyone who could give advice on automatically e-mailing data from a spreadsheet prior to saving and closing.

    Thank you very much!

    vcoder

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

    Re: Emailing results from XL automatically

    You can use SendObject in the Workbook_BeforeSave event in Excel.

    http://www.vbforums.com/showthread.php?t=402068

    Thread Moved
    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
    New Member
    Join Date
    Feb 2008
    Posts
    8

    Re: Emailing results from XL automatically

    Thanks for your reply RobDog,

    Could this be applied to worksheets within a workbook, because the workbook I am dealing with has a file size of at least 15MB. Alternatively, saving select results to a txt file is fine. Can I adapt the code to e-mail a newly saved txt file? I would be grateful if you could point me in the right direction.

    Many thanks,

    vcoder

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

    Re: Emailing results from XL automatically

    No, that only thing you can email with that method is a workbook.

    You can write all your desired data to a secondary temp workbook, open and email from within that instead so your not emailing the entire workbook.
    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
    New Member
    Join Date
    Feb 2008
    Posts
    8

    Re: Emailing results from XL automatically

    I see, for your help RodDog.

    Best regards,

    vcoder

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    8

    Re: Emailing results from XL automatically

    Hi Rob,

    Coming back to this, would you happen to know of code to e-mail a text file? It's just that I prefer to write my results in this way if possible.

    Thanks,

    vcoder

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Emailing results from XL automatically

    to send an email from vb /vba, there are several methods, the simplest is
    shellexecute "mailto" , but this requires the user to press send
    you can automate outlook to send email

    otherwise you need to look into cdont,
    or vbsendmail, which you can reference the dll to use the sendmail class, but you would need to get the winsock ocx
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    8

    Re: Emailing results from XL automatically

    Hi Westconn,

    Thanks for your reply. Would you happen to know of any tutorials on the methods you mentioned?

    Thanks,

    vcoder

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Emailing results from XL automatically

    robdog has tutorial for sending with outlook, see top post this forum

    search in the vb6 forum for vbsendmail, or google it and download the vbsendmail class and sample vb programs with the instructions
    if you don't have vb6 you will not be able to run the sample programs, but the code is easy enough to convert to vba, once you add a reference to the dll, make sure to register the dll
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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