VBA to attachment file from cell path

  • Hello All,


    I am trying to add attachment from path referenced in column I, but not working. Can anyone help me on this?


    Thank you a million.


  • Hello,


    Everything seems OK ...


    Check your Column I


    You do have to make sure to have the FULL Name including the path ...


    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • So Excel is telling me there is something wrong with the code, asking me to debug. Column I only has path, not file name. Can you please tell me what the format of the path should be, if it’s not just a path itself?


    Thank you very much for your help.

  • Hello again,


    To be clear, you cell should show the full path AND the file name with its extension :


    D:\Users\Jiajiexue\Documents\PDF\Invoice123.pdf

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

    Edited once, last by Carim ().

  • Please feel free to comment ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Sorry but I cannot see what is exactly in front of you eyes ... ;)


    In order to 100 % sure ... you can use File Explorer ... it will show you the full path as well as the exact file name and the extension ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • haha, no worries. So the path i have is copied from the "Copy Path" located on the left upper corner of the folder.


    Thanks.





    "P:\CDD Business Office\Medical Form - HIPPA Safe\2022\12, December 2022\Individual File\Espinoza.docx"



    Sorry but I cannot see what is exactly in front of you eyes ... ;)


    In order to 100 % sure ... you can use File Explorer ... it will show you the full path as well as the exact file name and the extension ...

  • Add the line:


    Code
    Msgbox mAttachment


    above the line to add the attachment and verify the path and file name appear correctly.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Thank you everyone, for your time on this.

    I figured it out, turns out I need to remove the "=" on line 20


    .Attachments.Add = mAttachment should be .Attachments.Add mAttachment (see Correction below)

    Edited 2 times, last by Carim: Added Code Tags ().

  • Pleased to hear you have managed to fix your problem :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Actually, I would like to take this 1 step further. I would like to have a company logo inserted in the email body rather than the email attachment as a file.


    .Attachments.Add "W:\Business\BUSINESS OFFICE\CDD Logo.jpg" is where the logo located in the shared drive.


    What do I need to do to make this happen?


    Thank you.


    Edited once, last by Carim ().

  • It's much easier if you can use an Outlook template message with the picture already embedded.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!