+ Reply to Thread
Results 1 to 9 of 9

VBA code not attaching PDF to email

  1. #1
    Registered User
    Join Date
    10-10-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    49

    VBA code not attaching PDF to email

    Hi all,

    I am not sure what I am doing wrong, or if it has something to do with my Outlook settings, however my code just wont work.

    Everything I have done so far is working fine. In short, my Excel file runs code to view each of 400 locations, creates a summary of each, converts each summary to PDF and saves in a C:\ location.

    When I get to the part when I attach the file to my outlook email it breaks. I have even tried copying some code from various sites and it still wont work.

    I have tried:

    .Attachments.Add ("C:\...")

    myattchments.Add "C:\..."

    etc...etc...

    Can anyone suggest a solution please?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code not attaching PDF to email

    This is the correct syntax.

    .Attachments.Add "C:\..."


    Double check if you have the correct full file path and file name. A common mistake is to forget to add a \ in between the path and the file name.

    What exactly happens when it 'breaks"; what is the error description?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,171

    Re: VBA code not attaching PDF to email

    .Attachments.Add "C:\..."

    is correct., I use this everyday, it works.

    Does the email send without attachments?
    Does the pdf exist at the point of attachment?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code not attaching PDF to email

    Can you post the current code?
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    10-10-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: VBA code not attaching PDF to email

    Hi,

    OK. I'm going to try it again and copy the error message.

    Can I ask, when the code is creating each PDF, it saves it using a cell reference which changes (hence creating 400 different PDFs. How can I reference that name when attaching the file (i.e."c:\Test\cell B3")

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code not attaching PDF to email

    Quote Originally Posted by AndyMan81 View Post
    Hi,

    OK. I'm going to try it again and copy the error message.

    Can I ask, when the code is creating each PDF, it saves it using a cell reference which changes (hence creating 400 different PDFs. How can I reference that name when attaching the file (i.e."c:\Test\cell B3")
    The syntax would look something like this...
    .Attachments.Add "C:\Test\" & Range("B3").Value


    If you need to loop through 400 cells, it would take more than just this line of code to do that. You would have to post your existing code and a detailed description of exactly what you want to do. Attaching an example workbook would help too.


    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  7. #7
    Registered User
    Join Date
    10-10-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: VBA code not attaching PDF to email

    Hi AlphaFrog,

    Everything is coded correctly. However when I test run the code, it keeps highlighting the .Attachments.Add "C:\Test\" & Range("G4").Value.

    I have no idea why. Ran the code without trying to attach the files i.e. created and saved 400 PDF files to my file location and everything works fine, however when inserting coding to attach them to email it keeps highlighting the above.

    I have never ran code that attaches files to Outlook before. Is there something I am missing (for example I ensured that MO Object Library was checked).

    It doesn't even give an error code, just highlights the code in yellow....

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA code not attaching PDF to email

    Can you post the code?

    What happens if you step through it?

    Which sheet/workbook are the PDF filenames coming from?

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code not attaching PDF to email

    Quote Originally Posted by AndyMan81 View Post
    Hi AlphaFrog,

    Everything is coded correctly. However when I test run the code, it keeps highlighting the .Attachments.Add "C:\Test\" & Range("G4").Value.

    I have no idea why. Ran the code without trying to attach the files i.e. created and saved 400 PDF files to my file location and everything works fine, however when inserting coding to attach them to email it keeps highlighting the above.

    I have never ran code that attaches files to Outlook before. Is there something I am missing (for example I ensured that MO Object Library was checked).

    It doesn't even give an error code, just highlights the code in yellow....
    Can't help you without seeing the whole code.

+ 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] VBA code exporting to PDF but not attaching the file to the email.
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-24-2016, 03:11 AM
  2. Attaching PDFs from PowerPoint and Email
    By Branbran10 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-21-2015, 09:07 AM
  3. export to pdf not attaching to the email
    By dantray02 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-30-2014, 01:23 PM
  4. [SOLVED] Attaching Picture to Email
    By Janie in forum Outlook Formatting & Functions
    Replies: 4
    Last Post: 07-30-2013, 04:23 PM
  5. Attaching files to an email
    By damage in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2011, 01:14 PM
  6. Attaching One Worksheet to Email
    By KeshnerH in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2005, 04:06 PM
  7. [SOLVED] attaching tabs to email
    By please help in forum Excel General
    Replies: 3
    Last Post: 01-19-2005, 04:06 PM

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