Save excel sheets to PDF on same path

Yogish

New Member
Joined
Mar 4, 2019
Messages
4
Hi ,

i am trying to save a multiple sheets from a workbook on to pdf in the same folder where excel workbook is saved, file name with specific cell value

below is the code i am using & i am getting, Application-defined or object-defined error, can someone please help on this, i know i am missing something.

Sheets(Array("Title", "Summary 1826", "Summary 1811", "Summary 1826 Entity ccy", "Summary 1811 Entity ccy")).Select
Sheets("Title").Activate


'ChDir ActiveWorkbook.Path & ""
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & " \ " & Range("D23") & " - " & Range("I22").Value, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Untested:
Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Sheets(Array("Title", "Summary 1826", "Summary 1811", "Summary 1826 Entity ccy", "Summary 1811 Entity ccy"))
        ChDir ActiveWorkbook.Path & "\"
        ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ws.Range("D23") & " - " & ws.Range("I22").Value, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Unfortunately your codes are not working, i am trying to combine all the sheets into one PDF so i have a code below to select all sheets, can you send any other codes

Sheets(Array("Title", "Summary 1826", "Summary 1811", "Summary 1826 Entity ccy", "Summary 1811 Entity ccy")).Select
 
Upvote 0
Try this version. I used the ranges in the sheet "Summary 1826" to name the file. Change the sheet name (in red) to suit your needs.
Code:
Sub Test()
    Application.ScreenUpdating = False
    Sheets(Array("Title", "Summary 1826", "Summary 1811", "Summary 1826 Entity ccy", "Summary 1811 Entity ccy")).Select
        ChDir ActiveWorkbook.Path & Application.PathSeparator
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheets("[COLOR="#FF0000"]Summary 1826[/COLOR]").Range("D23") & " - " & Sheets("[COLOR="#FF0000"]Summary 1826[/COLOR]").Range("I22").Value, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Sheets("Title").Select
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
the codes just work ones, if i run the macro again saving to different folder PDF are not saved. sorry not working
 
Upvote 0
i just saw the PDF are getting saved in the old path where file was originally saved , i need the file current path to be picked up for saving the PDF copies.
 
Upvote 0
The macro uses the path in which the workbook containing the macro is saved (ActiveWorkbook.Path). You have to make sure that when you open the macro workbook, you open it from the folder in which you want to save the pdf files. If the folder path never changes, then you can hard code that path instead of using "ActiveWorkbook.Path". If this is the case, what is the full path to the folder?
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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