+ Reply to Thread
Results 1 to 7 of 7

Please help: VBA not sending email when Outlook is open, only when closed

  1. #1
    Registered User
    Join Date
    07-23-2015
    Location
    NY
    MS-Off Ver
    2010
    Posts
    5

    Please help: VBA not sending email when Outlook is open, only when closed

    Hello all,

    I have a very simple code (below) that selects a range and send an email, the macros runs on Workbook_Open. If I just open the workbook myself, everything is working as expected (regardless of whether I have Outlook open or not). However, if I schedule the same spreadsheet to be open from Task Scheduler, it only works if I have Outlook closed. If the Outlook is open at that moment, I get "Method EnvelopeVisible of object '_workbook' failed". I tried various approaches and spend a day searching for a solution only, but nothing seems to help. I am running both 2010 Professional version of both Excel and Outlook. Again to summarize, when Outlook is open, the code only works when I run the spreadsheet, not when it is run from Task Manager (this task runs under my name with highest privileges).

    Thank you very much in advance for your help.

    -Konstantin

    Please Login or Register  to view this content.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Please help: VBA not sending email when Outlook is open, only when closed

    You could try another approach - to execute this code you would need to add a reference (under your VB editor Tools>References dialogue) to "Microsoft Outlook 14.0 Object Library"

    This does what you are after without using the EnvelopeVisible line causing you problems.

    Please Login or Register  to view this content.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    07-23-2015
    Location
    NY
    MS-Off Ver
    2010
    Posts
    5

    Re: Please help: VBA not sending email when Outlook is open, only when closed

    Thank you very much for your prompt response I tried three approaches with the code you suggested and here are the results:

    - Using Task Scheduler to open the spreadsheet when Outlook is open:
    The code breaks at “Set msOutApp = New Outlook.Application”, saying “ActiveX component cannot create object”
    - Using Task Scheduler to open the spreadsheet when Outlook is closed:
    The code breaks at “.Send”, saying “Application Error”
    - Manually opening the spreadsheet, when Outlook is open:
    It works and the email is sent, however the body is blank. Could you please advise how to send a selection in the body, as my previous code does?

    I believe that it has something to do with Task Scheduler. Not sure, if it is easy to replicate by it would be great if anyone could replicate this using Task Manager. Basically, all my code is in ‘main’ sub and then in ‘ThisWorkbook’, all I have is:

    Please Login or Register  to view this content.
    Again, thanks much for looking into this!


    Regards,
    Konstantin

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Please help: VBA not sending email when Outlook is open, only when closed

    Ah ha, the body.

    You would need to include a .body line - but I'm not sure how to make that send the sheet in-line (as it was doing). I guess if the scheduler isn't working on mine, just use yours

  5. #5
    Registered User
    Join Date
    07-23-2015
    Location
    NY
    MS-Off Ver
    2010
    Posts
    5

    Re: Please help: VBA not sending email when Outlook is open, only when closed

    sorry, but .Body does not solve the issue, plus it still does not work with Task Scheduler. Does anyone know how to overcome this issue? There seem to be no references on the Internet how to solve it...wondering if no one experienced the same issue before.

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Please help: VBA not sending email when Outlook is open, only when closed

    Sorry I'm not more help.

    I took your code and tested it and I can confirm that it works for me. When I run the task, the email is sent whether outlook is open or closed - so your code should be working

    I did notice while setting up the task, there is a send-email task. It looks like you could send the excel sheet as an attachment, which is not what you wanted originally - just thought I'd mention it since I saw it.
    Last edited by GeneralDisarray; 08-04-2015 at 09:47 AM.

  7. #7
    Registered User
    Join Date
    07-23-2015
    Location
    NY
    MS-Off Ver
    2010
    Posts
    5

    Re: Please help: VBA not sending email when Outlook is open, only when closed

    Thank you, I will keep tweaking it all.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Sending PDF with Outlook email
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-22-2015, 10:40 AM
  2. sending outlook email using vba
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-20-2014, 05:11 AM
  3. Sending Email with Outlook
    By cyberwerid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-27-2013, 05:34 PM
  4. Another requirement for sending email from vba outlook
    By joshshaji in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2012, 11:19 PM
  5. Sending Email via Outlook
    By jamsta1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2010, 12:46 PM
  6. Sending an email with Outlook Express not Outlook
    By Steven811 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-05-2010, 04:23 AM
  7. Sending Outlook email pop up box
    By jamphan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2007, 03:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1