Save Excel worksheet as PDF

Akshay_divecha

New Member
Joined
Mar 11, 2014
Messages
48
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
[B]    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & fName, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=True[/B]
        
End Sub
 

Akshay_divecha

New Member
Joined
Mar 11, 2014
Messages
48
Hi,

Tried below, but still the same error

Code:
C:\Users\divecak\Desktop\
 
Last edited:

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
5,996
Is fName a valid file name? Does it end with ".pdf"?

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

Akshay_divecha

New Member
Joined
Mar 11, 2014
Messages
48
Hi John,

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

Please help.
 

Akshay_divecha

New Member
Joined
Mar 11, 2014
Messages
48
Its the invoice no and customer name.. but that will keep on changing as an when invoice is generated.
 

Akshay_divecha

New Member
Joined
Mar 11, 2014
Messages
48
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"
 

Akshay_divecha

New Member
Joined
Mar 11, 2014
Messages
48
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

<colgroup><col width="86"></colgroup><tbody>
</tbody>

<colgroup><col width="64"></colgroup><tbody>
</tbody>
 

Forum statistics

Threads
1,081,749
Messages
5,361,070
Members
400,612
Latest member
mr_sound

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top