VBA save excel worksheet with workbook name plus text as a PDF

Ed_B

New Member
Joined
Mar 28, 2018
Messages
19
Office Version
  1. 2019
Platform
  1. Windows
This code only saves with the workbook name and not the text "Sample". What am I doing wrong? All answers appreciated Thanks, Ed

Sub SamplePDF()
Dim strFolder As String
Dim i As Long

'Find the position of the period in the file name
i = InStr(ActiveWorkbook.Name, ".")

Filename = Left(ActiveWorkbook.Name, i - 1) & " Sample "
Sheets(" Sample ").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub




 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You need to specify the filename when saving.
Code:
Sub SamplePDF()
Dim strFolder As String
Dim i As Long

    'Find the position of the period in the file name
    i = InStr(ActiveWorkbook.Name, ".")

    Filename = Left(ActiveWorkbook.Name, i - 1) & " Sample "

    Sheets(" Sample ").Select

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName, Quality _
         :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

End Sub
PS You'll probably also want to specify the folder the PDF is being save in, if you don't it'll get saved in what Excel considers the 'active' directory.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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