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 does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,575
Messages
6,125,612
Members
449,238
Latest member
wcbyers

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