Save Excel worksheet as PDF

Akshay_divecha

Board Regular
Joined
Mar 11, 2014
Messages
70
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
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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"
 
Upvote 0
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>
[TD="class: xl66, width: 86"][/TD]

</tbody>
[TABLE="width: 64"]
<colgroup><col width="64"></colgroup><tbody>[TR]
[TD="class: xl66, width: 64"][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top