+ Reply to Thread
Results 1 to 11 of 11

Outlook treats first email created by Excel differently

  1. #1
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Question Outlook treats first email created by Excel differently

    Hi folks,

    I have some VBA code in Excel which loops through a list of email addresses, creates an email to each one and saves the emails in the Outlook drafts folder.

    If Outlook is already running when my code starts then everything works as planned and all the emails are saved to Outlook's drafts folder.

    However, if Outlook is not already running when my code starts then the FIRST email always appears in the INBOX, and not always straight away. e.g. If I run my code without Outlook loaded and immediately start up Outlook afterwards, then all the emails except the first one are present in the Drafts folder; then, about a minute or so later, Outlook's Inbox will update to show "1 unread message" which is always the first email in the list. Clicking Outlook's send/recieve button does nothing to speed up the appearance of this rogue first email.

    I have worked around this odd behaviour by asking the user to start up Outlook if it is not already running, but I was just wondering whether any of you have experienced this before, or if anyone has any ideas for a less intrusive solution?

    Cheers

    EDIT: Forgot to say I already tried creating a "dummy" first email and just deleting it instead of saving it to the Drafts folder, but that made no difference. It seems to be the first ".Save" method on an Outlook.MailItem that causes this behaviour. Invoking the .Save method then immediately attempting to delete the saved message won't work either, because it is not in the Drafts folder, nor will it appear in the Inbox until many seconds later.
    Last edited by blackworx; 09-14-2011 at 08:21 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Outlook treats first email created by Excel differently

    Please post your VBA code so we can see which method you use to connect to Outlook.



  3. #3
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Outlook treats first email created by Excel differently

    Hi snb thanks for your quick reply.

    Code below. It's a sub from a userForm - can post the entire frx if you want.

    There are a few global variables/data types used that are not declared in the snippet but it should all be fairly clear.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Outlook treats first email created by Excel differently

    I think this would do

    Please Login or Register  to view this content.
    The faster the code the less you need a progressBar.

    I think the problem lies here:

    Please Login or Register  to view this content.
    You don't need this check as you can see in my code.

  5. #5
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Outlook treats first email created by Excel differently

    Thanks. Duly noted on the speed comment - I never use .Currentregion - more through ancient habit than choice and old habits die hard, especially when they are bad ones!

    Either way the progress bar is there only for pretties, as well as to notify completion without resorting to a modal dialogue, not because the code is taking too long.

    The problem can't lie with the check itself (which I do actually need - chkDraft is a local checkbox control with which the user specifies whether or not to save the emails as drafts or just send them - something I neglected to mention in my OP). However I noticed that you haven't used a .Close immediately following your .Save. Removing that solved the problem.

    Thanks again for your time and assistance

  6. #6
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Outlook treats first email created by Excel differently

    Actually I remembered why I don't as a rule use currentregion -- resilience against user error, in case they decide to remove entries from a list by simply clearing rows instead of deleting them.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Outlook treats first email created by Excel differently

    That's what userforms are for: preventing users to work in worksheets.

  8. #8
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Outlook treats first email created by Excel differently

    Not entirely sure what you mean by that. Personally I can't see the point of creating a whole front end for the management of some simple lists when I can code around the most predictable problems caused by giving users worksheet access very easily.

    If this program was meant for anything more than a small group of users then perhaps I could see the point of doing that, but then if that was the case then I wouldn't be using Excel+VBA for the job in the first place. This is just a simple quick and dirty distribution list program with a deliberately narrow set of features.

  9. #9
    Registered User
    Join Date
    11-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Outlook treats first email created by Excel differently

    I am facing the same problem. VBA is configured to send a single mail after generating a PDF.
    This draft email appears in the InBox and not immediately.
    ***

    Please Login or Register  to view this content.
    Moderator's Edit: Use code tags when you post code. To do so in future, select your code and click on # icon at the top of your post window.
    Last edited by arlu1201; 11-15-2012 at 08:47 AM.

  10. #10
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Outlook treats first email created by Excel differently

    It seems to me that this is something that's going wrong at the application level*. Removing the .Close method on the generated message caused things to work correctly for me, but then I was creating multiple messages. You could try adding a .Close after your .Save and see if that works?

    * The reason I say this is that I have observed the same behaviour in Office 2003 when using "Email > As attachment" from Excel's "File" menu. (Once the Outlook message editor opens, instead of sending the email click Save then close the editor. The saved message does not appear in Outlook's Drafts folder and some time later it appears in the Inbox.)
    Last edited by blackworx; 11-13-2012 at 10:36 AM.

  11. #11
    Registered User
    Join Date
    11-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Outlook treats first email created by Excel differently

    Yes it seems that VBA code is fairly standard and does not need any change. I tried to configure Outlook to use various accounts (corporate, personal etc) but could not resolve the issue.
    I get no errors if I SEND the mail instead of saving it to drafts so I have decided to send the attachment instantly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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