Create PDF macro button - PLEASE HELP

tomwhi

New Member
Joined
May 13, 2013
Messages
35
Hi Team,

Once again, I would really appricate your help!

Background:
I am creating a workbook - where the user selects difference criteria (slicers), which specifies which worksheet is relevent (out of 26 different options).

The user then inputs some varible which in turns updates the selected worksheet.

Problem:
Where I need help is the last stage. I want the user to be able to press a button and convert the specifed worksheet into a PDF (the worksheet name will be populate cell G10 of the 'Control Center' worksheet via a formula)

I hope I have provided enough information. Just ask if I need to clarify anything.

I am very much a novice when it comes to VBA...

THANK YOU FOR YOUR HELP!
Tom​
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I'll assume you want to save the pdf file to the same folder that holds the workbook with the specified sheet, and that the pdf file name is the name of the specified sheet.
Code:
Sub CreatePDF()
Dim fPath As String, wsNam As String
fPath = ThisWorkbook.Path & Application.PathSeparator
wsNam = Worksheets("Control Center").Range("G10").Value
Worksheets(wsNam).ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & _
    Worksheets(wsNam).Name & ".pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
 
Upvote 0
I'll assume you want to save the pdf file to the same folder that holds the workbook with the specified sheet, and that the pdf file name is the name of the specified sheet.
Code:
Sub CreatePDF()
Dim fPath As String, wsNam As String
fPath = ThisWorkbook.Path & Application.PathSeparator
wsNam = Worksheets("Control Center").Range("G10").Value
Worksheets(wsNam).ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & _
    Worksheets(wsNam).Name & ".pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub

PERFECT! use assumed correctly. Thank you
 
Upvote 0
Hey Joe,

There could be a requirement for the PDF file name to include information from another cell.

for example. cell G10 is the worksheet name (Location Transfer), and cell C13 is the name of the letter recipient (John Smith). Therefore, could we get the file to be named "Location Transfer - John Smith"?

Thanks again for your help.

Tom
 
Upvote 0
Hi,

believe I may have worked it out:

Code:
Sub CreatePDF()
Dim fPath As String, wsNam As String
fPath = ThisWorkbook.Path & Application.PathSeparator & Range("C13") & " "
wsNam = Worksheets("Control Center").Range("G10").Value
Worksheets(wsNam).ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & _
    Worksheets(wsNam).Name & ".pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,654
Members
449,245
Latest member
PatrickL

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