+ Reply to Thread
Results 1 to 10 of 10

Remove the error and clean my code to send mail automatically from excel

  1. #1
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Remove the error and clean my code to send mail automatically from excel

    Dear outlook Experts,
    I want to send the mail from excel automatically on a particular day on birthday. The program is working fine but only I have to open the outlook first and then excel to send the mail automatically. Actually I don't want to open the outlook before sending the mail from excel. I want to open the excel file only and the mail should deliver automatically from excel only and no need to open the outlook first.

    Please see the file and solve my problem. Please don't change the program because it's giving me desire output. Only change the code to send the mail from excel without opening the outlook first.

    Thanking you in anticipation.

    Mukesh
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Remove the error and clean my code to send mail automatically from excel

    I dont think you can do that.
    If you want to send an email without Outlook being opened, you will need to use the SMTP object or the CDO object.

  3. #3
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Remove the error and clean my code to send mail automatically from excel

    Hello jason_lee_91,
    Thank you for guidance. Please tell me which is the best option to send mail from excel without opening outlook automatically. Is there anything wrong in code? Tell me the setting to achieve the target.

    Waiting for your guidance.

    Thanking you in anticipation.

    Mukesh

  4. #4
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Remove the error and clean my code to send mail automatically from excel

    I dont think there is anything wrong with your code as much as it requires Outlook to be open while you do not want Outlook to be open.
    Just slightly different from what you need.

    It depends a little bit on your needs.
    Mainly, if you need security, this might not be such a good way because it requires you to write your password in the code.
    Alternatively, you could have it ask the user for a password.
    but thats not fully automated.

    In anycase, this is the way I send my emails.
    If you are at home, you can use for example gmails smtp server.
    If you are at work, you can use the company's smtp server.
    the VBA. Not whatever "Blat" is.
    http://www.dbforums.com/microsoft-ac...t-outlook.html

  5. #5
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Remove the error and clean my code to send mail automatically from excel

    One thing I myself might do differently is instead of using On Error GoTo lblLoop, I would probably find out why it throws an error and use an if statement.
    Its just that currently, any errors caused by that formula would stop the email from being sent.

    there could be many things that trigger an error.
    It could just be that the input was in the wrong format.
    If thats the case, maybe the emails will never get sent and you might not know that there is actually a problem in your code.
    But thats entirely just my opinion/preference.

    Also, I have heard that people feel that GoTo statements are slightly harder to read in many cases.

  6. #6
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Remove the error and clean my code to send mail automatically from excel

    Hello jason_lee_91,
    As per your suggestion it's not a safer way. At present only I have to open the outlook before opening excel file to send the message. It's better than inserting password in code. I think that I shall continue the present code and system to open outlook first then excel.

    Give me your opinion on it so that I will close this thread.

    Thank you.

    Mukesh

  7. #7
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Remove the error and clean my code to send mail automatically from excel

    Sounds like a good idea to me.
    You could even have Excel open up Outlook and then run the macro after waiting a certain time (since you need to give outlook a chance to open)

    If you put this inside the same module as your "Anniversary" sub-routine, it shoudl work.




    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Remove the error and clean my code to send mail automatically from excel

    Hello jason_lee_91,
    Really it's good idea to open the outlook from excel but I want some modification in it. I don't want to run 2 macros for a single task. I want to click on anniversary macro then first the macro will open the outlook and run anniversary then. After certain time for example 1 minute the outlook will automatically closed. It will save my time to close the outlook after running the macro manually and speed up the task.
    Please see the attachment.

    Mukesh
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    07-16-2012
    Location
    Ontario Canada
    MS-Off Ver
    Excel 2010
    Posts
    124

    Re: Remove the error and clean my code to send mail automatically from excel

    First, about putting your code together.
    The Shell command tells your computer to open Outlook.
    And Outlook takes a couple seconds to load.
    So you have to wait a bit before you run the code.
    If you look at the Application.OnTime method, what it is doing is it calls another macro at a certain time.
    It does not pick up where it left off.
    So if you want to put the two pieces of code together, you would have to think of a new method of waiting for Outlook to open.
    I have seen some people do this with loops but I have never used methods like this before.
    But if you Google it, there are tons of results.
    I just personally dont like them is all.

    Second, for closing Outlook.
    Unfortunately, there doesnt appear to be a close command for Outlook.

    These are some of the reasons I usually use the SMTP object.
    The way I deal with passwords, is I put an input box for the user to enter an email and a password.
    Then, if there is any sort of error during the send command, I check for the error code and if it is a connection issue, I just stop the macro.
    That way, the password isnt actually stored in the code.
    The caveat of this is that you have to actually be at your computer.
    But since you are going to run the Anniversary macro yourself anyways, I dont think this is a problem.

  10. #10
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Remove the error and clean my code to send mail automatically from excel

    Hello jason_lee_91,
    Thank you for your guidance. Now my problem is solved.

    Mukesh

+ 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. Code to send an e-mail. Don't send if attachment not found
    By thedon_1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2012, 05:41 PM
  2. Send mail from excel sheet to oulook automatically
    By hai_krk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2009, 03:42 AM
  3. Automatically send Mail for Due Dates from Excel
    By Kohinoor in forum Excel General
    Replies: 1
    Last Post: 03-20-2009, 12:10 PM
  4. Can excel automatically send e-mail when particular cell is change
    By ivica in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-20-2006, 05:55 PM
  5. [SOLVED] Macro to automatically open a website or send an e-mail in excel
    By Byron in forum Excel General
    Replies: 3
    Last Post: 04-07-2006, 04:10 AM

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