Print to PDF - Fit to 1 page wide + automate saved file name

Iceshade

Board Regular
Joined
May 22, 2017
Messages
104
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

I am very new to VBA and need some help please. I have 2 work sheets which I want both to be saved into the 1 PDF. I can get this working with the following piece of code however I face 2 issues:

1) I can't seem to get it to fit to 1 page wide (I get only left half of worksheet in the pdf)
2) I prompt user for filename to save, how do I streamline this better? It very clunky and unprofessional to do this via an Inputbox but with my limited knowledge it's the only way I know how.

Here is the snippet:

VBA Code:
'Grab both sheets and print to PDF
Dim str As String, myfolder As String, myfile As String
Sheets(Array("Print Sheet1", "Print Sheet2")).Select
str = "Do you want to save these sheets to a single pdf file?" & Chr(10)
For Each sht In ActiveWindow.SelectedSheets
str = str & sht.Name & Chr(10)
Next sht

answer = MsgBox(str, vbYesNo, "Continue with save?")
If answer = vbNo Then Exit Sub

With Application.FileDialog(msoFileDialogFolderPicker)
.Show
myfolder = .SelectedItems(1) & "\"
End With

myfile = InputBox("Enter filename", "Save as..")

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
myfolder & myfile _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

Would really appreciate some guidance here please - thank you
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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