Using VB to print and save one worksheet from another as a PDF with the file name based on a cell value

tommyz03

New Member
Joined
Aug 26, 2017
Messages
1
I am using an ActiveX button to execute the printing of one sheet from another, this is working. But I am also am trying to save the second sheet as a PDF based on a cell value in the first worksheet, in the same code.

Here is the code:

Private Sub CommandButton1_Click()


'Print only "Cal Sheet"
Sheets("Cal Sheet").PrintOut




Dim StrFilename As String
Dim rngRange As Range


Set rngRange = Worksheets("Cal Sheet").Range("C13")
StrFilename = rngRange.Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:="S:\Calibration Bench\CS20\Bencch Data\S-Series" & StrFilename & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False


Sheets("Cal Sheet").Select


End Sub

the print function works, but the save function saves the wrong sheet and doesn't give the name from the data in C13.

any help would be greatly appreciated - thanks!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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