+ Reply to Thread
Results 1 to 10 of 10

Macro to email sheet not working in Outlook 2007

  1. #1
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Macro to email sheet not working in Outlook 2007

    Hello all. I have the following code that works for Outlook 2003 but does not work for Outlook 2007. Does anyone know what changes need to be made so this macro will work in both Outlook versions?

    Please Login or Register  to view this content.
    Thanks,
    Andrew
    Last edited by drewship; 02-17-2010 at 10:29 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Macro to email sheet not working in Outlook 2007

    Works for me on 2007 ... do you have a C:\temp folder on your machine ?

  3. #3
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Macro to email sheet not working in Outlook 2007

    Hello DonkeyOte. When we were first upgraded to Vista/Office 2007 I noticed that I no longer had access to the C:\ drive so changed the code to place the file in the C:\Temp. In the code you can still see where I commented out the original directory location. What used to happen is that the macro would run, I would get a popup asking if I wanted to allow an external program to open Outlook, I clicked yes, Outlook opened and the email was sent. Now, there is no indication that an email is sent but the code does tell me it has completed. I look at my sent items and the C:\Temp folder but there is nothing there.

    I have attached a test workbook. Just cancel out of the external database requests. All data necessary has been hard entered. I am using my laptop with XP and Outlook 2003. When I click on the email button (K1) on the All_Report, the above actions occur, and I have opened my C:\Temp folder and watched the file save and then be deleted. Additionally, I can see the emails in the Outbox before they are sent. I will not have access to Outlook 2007 until Tues when I go back to the office, but when I tried the same actions over the past several days at work, I see no indication of an email.

    Thanks,
    Andrew
    Attached Files Attached Files

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Macro to email sheet not working in Outlook 2007

    I just tested again and all was ok... I can't recall having to change the Trust Settings in OL at all...
    (ie High Security in OL won't make a difference given the VBA is not in OL)

    If no one else resolves in the meantime I'd suggest stepping through with F8 and see what happens step by step...
    looking at the code it should do "something" even it's a debug or mailing a mail item with no attachment...
    Last edited by DonkeyOte; 02-12-2010 at 12:34 PM.

  5. #5
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Macro to email sheet not working in Outlook 2007

    Thanks DonkeyOte. I will step through Tues with the outbok and C:\Temp open to see if the file and/or email are created. I will post back with my results.

    Andrew

  6. #6
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Macro to email sheet not working in Outlook 2007

    Just finished stepping through the code and I saw the file being saved to the C:\Temp folder but Outlook never requested permission to send an email or did anything to indicate that the code had tried to open it.

    I will keep looking. It may be that there is some setting in Outlook 2007 that is preventing this but I have not found anything yet.

    Thanks,
    Andrew

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Macro to email sheet not working in Outlook 2007

    Hi,
    Just tested it. Here it works without any problem.

    Buran
    If you are pleased with a member's answer then use the Star icon to rate it.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Macro to email sheet not working in Outlook 2007

    Quote Originally Posted by Andrew
    Just finished stepping through the code and I saw the file being saved to the C:\Temp folder but Outlook never requested permission to send an email or did anything to indicate that the code had tried to open it.
    Andrew, I'd suggest disabling the On Error Resume Next statement prior to the With OutMail line (by commenting it) ... then step through again and see if an error is raised at some point within that section. Let us know.

    We're most probably all missing something obvious in terms of config... I can't recall setting anything in OL 2007 to permit automation but it was a while ago.... I'll ask some others.

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Macro to email sheet not working in Outlook 2007

    None of the Programmatic Access options should stop it working - they just determine whether you get warned or not.
    First places to start would be:
    1. Change the email address to send to yourself and see if you receive it.
    2. Change the .Send line to .Display to see if the email is created properly
    3. As DO said, remove the On Error Resume Next line.

    As an aside, I don't really get the method of copying the workbook, killing and closing it. I think it would be better to use SaveCopyAs, attach that copy and then kill that copy rather than trying to kill the open workbook before closing it.
    Remember what the dormouse said
    Feed your head

  10. #10
    Forum Contributor
    Join Date
    04-30-2009
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    496

    Re: Macro to email sheet not working in Outlook 2007

    Thanks romperstomper, " Change the .Send line to .Display to see if the email is created properly" did the trick!! It not only let me see the email but I was able to send it. I also made the changes you recommended. Everything is tested and working great. Thanks everyone!!

    Andrew

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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