+ Reply to Thread
Results 1 to 16 of 16

How to attach excel file in outlook mail with conditions?

  1. #1
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    How to attach excel file in outlook mail with conditions?

    Hi all,

    Hope all's well.

    I have a macro which when run, attaches excel file in outlook mail by renaming it.

    Everything's fine except for below points.

    1.

    2. File to be renamed contains last working date. In case of weekend, it should show date including Saturday and Sunday such as 22 - 24/Sep/2023.

    3. Point 2 to be applied to the body as well.

    "Please find attached ZEU_BATCH errors report as on 22 - 24/Sep/2023."

    4. The text "Also, there are no decommissioning errors till time." should be highlighted in yellow in mail.


    Please Login or Register  to view this content.
    Can someone please help?
    Attached Files Attached Files
    Last edited by rizwanulhasan; 09-26-2023 at 10:57 AM.

  2. #2
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    1st point is resolved using below code.

    Please Login or Register  to view this content.
    Just left with rest of the points.
    Last edited by rizwanulhasan; 09-26-2023 at 09:29 AM.

  3. #3
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to attach excel file in outlook mail with conditions?

    Does this work for you?


    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    @ByteMarks

    Many thanks for your response but I get the below error.
    Attached Images Attached Images

  5. #5
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to attach excel file in outlook mail with conditions?

    Sorry, I think there's a typo in the line above. it should be .xlsx not .xlxs

    If it still fails, then you could try specifying the full path and file format, e.g.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    @ByteMarks

    Tried both options. Unfortunately after macro is run, excel crashes and shuts down.

    Please Login or Register  to view this content.
    Last edited by rizwanulhasan; 09-27-2023 at 01:51 PM.

  7. #7
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to attach excel file in outlook mail with conditions?

    Not sure why your Excel is crashing. I saved the code below in a module of an xlsm file and it works as intended. I.E., it attaches and xlsx copy to an email.


    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    @ByteMarks

    The above code works perfectly, without crashing I just need to check the dates on a Monday.

    Just 1 request. After an excel file is created and renamed and before outlook is opened, can the file be saved to below location


    C:\Users\rh294814\OneDrive - GSK\My Data\Others

  9. #9
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to attach excel file in outlook mail with conditions?

    Great.

    You could try:

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    Perfect

    Just that the file attached shows %20...% although file saved on local drive is correctly renamed.
    Attached Images Attached Images

  11. #11
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to attach excel file in outlook mail with conditions?

    What if you use

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    @ByteMarks

    Sorry but may i know where to add it

  13. #13
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to attach excel file in outlook mail with conditions?

    If you replace the existing line in the part that creates the email.


    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    Nope. Same error

  15. #15
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to attach excel file in outlook mail with conditions?

    Maybe save an additional copy to local temp to attach and then delete it at the end.


    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    777

    Re: How to attach excel file in outlook mail with conditions?

    @ByteMarks

    Working perfectly now. Thanks a ton.

+ 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] Converted from Excel to PDF. Attach to an Outlook E-Mail
    By leebird in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-21-2017, 10:44 AM
  2. General: attach file in Outlook 2010 mass mail merge
    By Karnik in forum Excel General
    Replies: 3
    Last Post: 04-15-2016, 08:04 PM
  3. [SOLVED] screenshot text file and embed in outlook mail through excel with mail info
    By bmbalamurali in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 01-11-2015, 08:21 PM
  4. [SOLVED] How to prompt user to select file to attach to an E-Mail (Excel to Outlook)
    By TheLittlePrince in forum Outlook Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 05:33 AM
  5. [SOLVED] attach file from folder on c:\ to outlook mail and send
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2013, 11:33 AM
  6. Outlook - Save Worksheet as PDF and attach to outlook mail
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2012, 10:19 AM
  7. code to attach the draft mail in new compose mail as attachment in outlook 2010
    By priya1987 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2012, 08:38 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