Error file path in not correct while attaching in email
Results 1 to 4 of 4

Thread: Error file path in not correct while attaching in email

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Error file path in not correct while attaching in email

    Hello I am new of VBA.
    I can generate the pdf with new name every time, however i am not able to attached latest generated file in email. it is giving me me error
    " Path does not exist, verify the path in correct."

    here is the code. please help me expert



    Sub sendReminderMail()
    ChDir "C:\Users\Vinod\Desktop\Latest Billing"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
    ActiveSheet.Range("Q10").Value, OpenAfterPublish:=True
    filelocation = "C:\Users\Vinod\Desktop\Latest Billing"


    Dim OutLookApp As Object
    Dim OutLookMailItem As Object
    Dim myAttachments As Object
    Dim maildest As String


    Set OutLookApp = CreateObject("Outlook.application")
    Set OutLookMailItem = OutLookApp.CreateItem(0)
    Set myAttachments = OutLookMailItem.Attachments
    maildest = ActiveSheet.Range("b18").Value


    With OutLookMailItem
    .To = maildest
    .Subject = "Data"
    .Body = "Thank you for contacting us. Your estimate can be viewed,_ printed and downloaded as PDF from the link below."
    .Attachments.Add Sheets("Invoice").Range("Q10").Value & "" & ".pdf"
    '.send
    .Display
    End With


    Set OutLookMailItem = Nothing
    Set OutLookApp = Nothing




    End Sub

  2. #2
    Board Regular
    Join Date
    Oct 2007
    Posts
    5,807
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Error file path in not correct while attaching in email

    Just guessing, but maybe:
    Code:
    Sub sendReminderMail()
    Dim PDFfullName As String
    PDFfullName = "C:\Users\Vinod\Desktop\Latest Billing\" & ActiveSheet.Range("Q10").Value & ".pdf"
    ChDir "C:\Users\Vinod\Desktop\Latest Billing"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
    PDFfullName, OpenAfterPublish:=True
    
    Dim OutLookApp As Object
    Dim OutLookMailItem As Object
    Dim myAttachments As Object
    Dim maildest As String
    
    
    Set OutLookApp = CreateObject("Outlook.application")
    Set OutLookMailItem = OutLookApp.CreateItem(0)
    Set myAttachments = OutLookMailItem.Attachments
    maildest = ActiveSheet.Range("b18").Value
    
    
    With OutLookMailItem
    .To = maildest
    .Subject = "Data"
    .Body = "Thank you for contacting us. Your estimate can be viewed,_ printed and downloaded as PDF from the link below."
    .Attachments.Add PDFfullName
    '.send
    .Display
    End With
    
    
    Set OutLookMailItem = Nothing
    Set OutLookApp = Nothing
    
    End Sub
    If that doesn't work, what is the value of ActiveSheet.Range("Q10") and Sheets("Invoice").Range("Q10")? Is "Invoice" the active sheet?

  3. #3
    New Member
    Join Date
    Jun 2019
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Error file path in not correct while attaching in email

    Quote Originally Posted by John_w View Post
    Just guessing, but maybe:
    Code:
    Sub sendReminderMail()
    Dim PDFfullName As String
    PDFfullName = "C:\Users\Vinod\Desktop\Latest Billing\" & ActiveSheet.Range("Q10").Value & ".pdf"
    ChDir "C:\Users\Vinod\Desktop\Latest Billing"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
    PDFfullName, OpenAfterPublish:=True
    
    Dim OutLookApp As Object
    Dim OutLookMailItem As Object
    Dim myAttachments As Object
    Dim maildest As String
    
    
    Set OutLookApp = CreateObject("Outlook.application")
    Set OutLookMailItem = OutLookApp.CreateItem(0)
    Set myAttachments = OutLookMailItem.Attachments
    maildest = ActiveSheet.Range("b18").Value
    
    
    With OutLookMailItem
    .To = maildest
    .Subject = "Data"
    .Body = "Thank you for contacting us. Your estimate can be viewed,_ printed and downloaded as PDF from the link below."
    .Attachments.Add PDFfullName
    '.send
    .Display
    End With
    
    
    Set OutLookMailItem = Nothing
    Set OutLookApp = Nothing
    
    End Sub
    If that doesn't work, what is the value of ActiveSheet.Range("Q10") and Sheets("Invoice").Range("Q10")? Is "Invoice" the active sheet?

    Thanks a lot for your time to review my request
    Q10 is a variable value, which is set the file name such as "QST040601, QST040602, QST040603 ...." and and I want to attached same pdf file as Q10 cell value
    Exm
    Q10 cell = QST040603 eamil attached file: QST040603.pdf
    Q10 cell = QST040604 eamil attached file: QST040604.pdf

    Regards

  4. #4
    New Member
    Join Date
    Jun 2019
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Error file path in not correct while attaching in email

    Hello John,

    your save my life, thank a lot for your quick code

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •