Save file as PDF excluding one sheet

skf786

Board Regular
Joined
Sep 26, 2010
Messages
156
hi,

i want a macro to save the file as PDF on desktop excluding the sheet named 'Home' There are four other sheets in the file named 1,2,3,4.

File name should be from cell A1 on Home sheet plus dd/mm/yyyy.

Thank you

KF
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
is the macro permitted to close the workbook immediately after creating the pdf ?
- one method would be to save the workbook, delete the unwanted sheet, create pdf, close the workbook without saving

Otherwise a new workbook needs to be created - which you may prefer.
- if so is that workbook to be retained or deleted ?
- should original workbook be left open or closed ?
 
Upvote 0
No, the workbook has to remain open and the saved PDF has to open after saving as well.

Would prefer a new workbook to be created which may be deleted.
 
Upvote 0
I forgot about a simpler method
- assumes the code is in the workbook containing the 5 sheets
- dd/mm/yyyy contains illegal characters hence dd-mm-yyyy
- amend fPath C:\Test\Folder\SubFolder

Try this
VBA Code:
Sub CreatePDF()
    Dim fName As String, fPath As String
    fPath = "C:\Test\Folder\SubFolder"
    fName = Sheets("Home").Range("A1").Value & " " & Format(Date, "dd-mm-yyyy")
    fPath = fPath & "\" & fName & ".pdf"
    ThisWorkbook.Sheets(Array("1", "2", "3", "4")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
    ThisWorkbook.Sheets("Home").Select
End Sub
 
Upvote 0
Thank you, this works fine. Is it possible to give a standard fPath so that it works on desktop of any user?

Thanks again

KF
 
Upvote 0
try this

VBA Code:
fPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
MsgBox fPath
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,293
Members
448,564
Latest member
ED38

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