+ Reply to Thread
Results 1 to 12 of 12

macro which sends email with attachment

  1. #1
    Registered User
    Join Date
    11-27-2017
    Location
    Poland
    MS-Off Ver
    2016
    Posts
    6

    macro which sends email with attachment

    Hi,

    I need some small assistance with macro which sends an email with attachment.

    Please Login or Register  to view this content.
    Everything what is above works, until it finds a file on the harddrive. When there is no file on my harddrive I get an error. How can I fix the code so that emails will be sent even if there is no attachment? I would like to get a message that there is no file, and send it anyway, or just send without attachment.

    Thank you :-)

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: macro which sends email with attachment

    Maybe a simple if statement? Haven't tried it, don't see a reason for it not to work though.

    Please Login or Register  to view this content.

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: macro which sends email with attachment

    Focusing on this part:
    "would like to get a message that there is no file, and send it anyway"
    it could go:
    Please Login or Register  to view this content.
    At some stage you'd probably like to chnage:
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.
    to have a mail sent immediately.
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    11-27-2017
    Location
    Poland
    MS-Off Ver
    2016
    Posts
    6

    Re: macro which sends email with attachment

    Hi davesexcel,
    Thank you for the response.
    I tried your way but it didnt work. Maybe the reason is that in cell dane!F31 I always gets a result. It means that according to oder informations in the sheet i get a joint text as below:

    Please Login or Register  to view this content.
    And then, excel is looking for it on my harddrive. Do you have an idea what can I change?

    THanks!

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: macro which sends email with attachment

    OK, so the cell is not empty, just file does not exist.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-27-2017
    Location
    Poland
    MS-Off Ver
    2016
    Posts
    6

    Re: macro which sends email with attachment

    Hi Kaper,

    Thank you for the response. It is very useful. There was small misspelling in "errore" but i managed ;-)
    Anyhow, i get a message about failure, but the mail does not displays.
    After message, i get "Run time error '440': Indeks tablicy poza zakresem."
    Do you know what might be the problem?

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: macro which sends email with attachment

    In which line code stops? (after it stops press debug - one of code lines shall be highlighted yellow.).

    The problem could be also outside of this code snippet - it runs well on my computer, see screenshot, but I had to change hyphen (-) to underscore (_) in sub name
    Attached Images Attached Images

  8. #8
    Registered User
    Join Date
    11-27-2017
    Location
    Poland
    MS-Off Ver
    2016
    Posts
    6

    Re: macro which sends email with attachment

    It stops in ".Display" line.

    Przechwytywanie.JPG

  9. #9
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: macro which sends email with attachment

    Try running in an empty sheet does it stop too?
    How long are texts in cells in column F?

  10. #10
    Registered User
    Join Date
    11-27-2017
    Location
    Poland
    MS-Off Ver
    2016
    Posts
    6

    Re: macro which sends email with attachment

    in empty sheet it works.
    the text is quite long, see below:

    \\ampols200\Dzial Techniczny\TECHNOLOGIA\T-pipe_technologie\C_300x300_1_5000.zip

  11. #11
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: macro which sends email with attachment

    How about checking if file exists before attempting to use it as attachment:

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-27-2017
    Location
    Poland
    MS-Off Ver
    2016
    Posts
    6

    Re: macro which sends email with attachment

    This is great Kaper.
    Thanks a lot for your help! Now I have to go line after line to understand how you have done that :-)

    Once again, thank you!

+ 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. macro that sends email
    By rhndrixxxx in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2015, 04:42 PM
  2. Macro that sends a formatted email from Excel
    By suzannahdove in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2014, 03:41 PM
  3. macro which sends email to few receipients with a standard message
    By megtoma in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-21-2014, 07:57 AM
  4. HELP! Need help with macro that automatically sends email when...
    By KngCharming in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-28-2013, 01:01 PM
  5. Macro that sends email automatically once a week?
    By GTfan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2012, 02:44 PM
  6. A macro that looks up a email from sheet2 and sends email
    By AdderLee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2012, 02:24 PM
  7. Sends Attachment with Email
    By pcargila in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-06-2008, 09:08 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