Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Save Excel worksheet as PDF

  1. #1
    New Member
    Join Date
    Mar 2014
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Save Excel worksheet as PDF

    Hi Exports,

    I am trying to save excel worksheet to PDF however encountering runtime error 1004 with the msg with reads as "Document not saved. The document may be open, or an error may have been encountered while saving.

    when clicked on deburg, below in bold is highlited in yellow.

    Kindly help to fix this.

    Code:
    Sub DesktopPDF()
    
    'Set path to Desktop
        fPath = "C:\Users\divecak\Desktop"
    
    'Build File Name from Sheet1 I8, A11 & H11
        fName = Sheets(1).Range("I8") & " - " & _
                Sheets(1).Range("A11") & " - " & _
                Sheets(1).Range("H11")
    
    'Export as PDF to Desktop
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & fName, _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=True
            
    End Sub

  2. #2
    MrExcel MVP
    Join Date
    Oct 2007
    Posts
    5,896
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Try adding a back slash at the end of the fPath string.

  3. #3
    New Member
    Join Date
    Mar 2014
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Hi,

    Tried below, but still the same error

    Code:
    C:\Users\divecak\Desktop\
    Last edited by Akshay_divecha; Oct 18th, 2019 at 08:34 AM.

  4. #4
    MrExcel MVP
    Join Date
    Oct 2007
    Posts
    5,896
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Is fName a valid file name? Does it end with ".pdf"?

    Try it with a fixed file name:
    Code:
    fName = "Test.pdf"

  5. #5
    New Member
    Join Date
    Mar 2014
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Hi John,

    It worked but i need the file name from cells mentioned in the code.

    Please help.

  6. #6
    MrExcel MVP
    Join Date
    Oct 2007
    Posts
    5,896
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Save Excel worksheet as PDF

    What is the value of fName from the cells?

  7. #7
    New Member
    Join Date
    Mar 2014
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Its the invoice no and customer name.. but that will keep on changing as an when invoice is generated.

  8. #8
    New Member
    Join Date
    Mar 2014
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Hi John,

    I tried changing the code but still there is an error

    Code:
        fName = Sheets(1).Range("I8") & " - " & _
                Sheets(1).Range("A11") & " - " & _
                Sheets(1).Range("H11") & ".pdf"

  9. #9
    MrExcel MVP
    Join Date
    Oct 2007
    Posts
    5,896
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Quote Originally Posted by Akshay_divecha View Post
    Its the invoice no and customer name.. but that will keep on changing as an when invoice is generated.
    Yes, but what is the actual value? Give examples - I want to see if it's a valid file name.

  10. #10
    New Member
    Join Date
    Mar 2014
    Posts
    33
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Save Excel worksheet as PDF

    Hi,

    Since i have not access to upload excel, i will try explaining the requirements .

    value in cell I8 = 123/45679/000

    value in cell A11 = abcdecdghdh

    value in cell H11 = EGLV130900062647

    so the file name should be 123/45679/000 - abcdecdghdh - EGLV130900062647

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
  •