I think theres a small error in this code (macro for saving as PDF)

dannyok90

Board Regular
Joined
Aug 30, 2016
Messages
115
Morning All,

I'm fairly new to code and I keep getting errors every time I write some! :mad:

I have written this with help from Google etc.

When I run the macro it says 'document not saved, the document may be open, or an error may have been encountered when saving.'
and the debugger is picking up an error on the rng.export line

Note: Ive x'd out some of the file path

Any Help? :D


Code:
Sub savepdf()
Dim Rng As Range
Dim fPathFile As String, fncb1 As String
Dim LstRw As Long
    LstRw = Cells(Rows.Count, "J").End(xlUp).Row
    fncb1 = Range("B1").Value
    Set Rng = Range("A1:J" & LstRw)
    fPathFile = ("[URL="file://\\XXX.XX\RT\XXXX\DER\XX-XXXXX$\Tasks\XXXXX+\400+\XXXXXX"]\\XXX.XX\RT\XXXX\DER\XX-XXXXX$\Tasks\XXXXX+\400+\XXXXXX[/URL]  XXXXXXXX XXXXXX XXXXXXX XXXXXX XXX XXXXXXX\Deliverable")
    Rng.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPathFile & fncb1 & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,224,834
Messages
6,181,243
Members
453,026
Latest member
cknader

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