.Attachments.Add Issues

  • So this worked... at one point. Now, for some reason, it's throwing a code! I'm not sure what the issue is as I've gone through this with a fine tooth comb... hopefully someone else has either a) seen this issue and resolved it, or (more likely) see a problem with my coding that is causing this to come up this way.


    Anyone have any thoughts here? I'm lost and not sure what direction to head...


    Thx.
    MA

  • Re: .Attachments.Add Issues


    Try adding the full path for the file you are trying to attach.

    Code
    .Attachments.Add "C:\AFolder\TheFolderTheAttachmentIsIn\PDFFile.pdf"


    You might also want to specify the folder when you create the file too.


    If you don't specify the folder/path when VBA will use the currently active folder for creating the file.

  • Re: .Attachments.Add Issues


    I gave the "PDFFile" change a try, but to no avail, it came up with the same error message.
    "Runtime Error -2147024894 (80070002)
    Cannot find this file. Verify the path and file name are correct."


    Norie - when looking at this, does it matter if the filename is temporary? It seems to work if i change the filename from PDFFile.pdf to PDFFile1.pdf, but only for a few rounds then throws the same error message again. I've looked over other message boards and it seems others have had this same issue in the past??


    I REALLY appreciate everyones help!

  • Re: .Attachments.Add Issues


    You should always specify the path.


    Like I said if you don't VBA will use the current active directory which, if you are lucky, might work but isn't guaranteed to.

  • Re: .Attachments.Add Issues


    This line :


    Code
    #2
    
    
     .Attachments.Add "PDFFile.pdf" '****************This seems to be where the code is coming from********************



    Is referring to this variable further up in the macro :


    Code
    #1
    
    
    'Create new PDF file name including path and file extension
                PDFFile = destfolder & Application.PathSeparator & "Order Confirmation" & "_" & "NE06-" & [Dashboard!e7].Value _ 
                & ".pdf"


    So ... as Norie indicated, hardcode the path (in line #1) where the new PDF will be created rather than having it temp.


    Then in the second line, still edit it to read .Attachments.Add "PDFFile" as it will reference the same variable in #1



    If you don't want that PDF to be a lasting file in the folder you could add another line near the bottom of your macro to delete that PDF file.

  • Re: .Attachments.Add Issues


    Logit


    I think you might be on to something but "PDFFile" will no reference any variable, it's a literal string.


    If you wanted to refer to a variable with the name 'PDFFile' you would use this.

    Code
    .Attachments.Add PDFFile
  • Re: .Attachments.Add Issues


    I have yet to format a macro in this manner. My paths have always been typed out in full ( "C:\Users\My\Desktop" etc. )
    My mind was seeing it as a variable for some reason. Old age ... :?



    Usually takes me two errors to get the right way ... what did T. Edison say "I didn't fail 1,000 times. I proved how not to make a light bulb 1,000 times"



    That's my excuse and I'm sticking to it.

Participate now!

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