Link to home
Start Free TrialLog in
Avatar of martywal
martywal

asked on

Saving Worksheet to PDF in Excel

Hi Experts,

I'm having an issue with trying to save worksheets as PDF's in Excel. My Script looks like this:

        Sheets("ORF - Process Summary").Visible = True
        Sheets("ORF - Process Summary").Select
        Sheets("ORF - Process Summary").Copy
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            "\\svrau570bsm01\" & Range("ORFraiseLAN").Value & "$\My Documents\Classification Tool\" & Range("CURRENTorf").Value & " Process TEST.pdf" _
            , Quality:=xlQualityStandard, IncludeDocProperties:=False, _
            IgnorePrintAreas:=False, OpenAfterPublish:=True
        ActiveWindow.Close

I think that just having selected the sheet should be sufficient before running the export. I'm currently getting a runtime error '1004': Method 'Range' of object '_Worksheet' Failed

(the code is attached to a button on the worksheet I'm trying to save as a pdf).

Ultimately I want to save a number of worksheets as PDF's

Any help appreciated
Avatar of Rgonzo1971
Rgonzo1971

Hi,

Are your named ranges correct and at this stage of the code available?

Regards
You can use this code to verify that your ranges are "available":

Function isNameRngExist(myRng As String) As Boolean
    On Error Resume Next
    isNameRngExist = Len(ThisWorkbook.Names(TheName).Name) <> 0
End Function

If not, you may need to fully qualify them.
Avatar of martywal

ASKER

Hi guys,

Sorry not been on this for the last few days.
Thanks for your input!

In terms the function, if I just add that to a module that should work when the error pops up, right?

I'm wondering if stopping the script from opening the PDF may fix the issue.
ASKER CERTIFIED SOLUTION
Avatar of Julie Thomas
Julie Thomas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi experts.
Sorry again for the lack of traction on this.
Indeed it looks like I'd stepped out of where I needed to be to save the pdf.
Appears fixed now.
I'll close in next day or two
Thanks for your help.
Martywal