Excel VBA for PDF Creater - 2 pages per sheet

Pritesh_B

New Member
Joined
Nov 7, 2017
Messages
1
Hi all ,

I'm good in Excel with Formulas and Pivot Tables but have like 0.5/10 understanding of VBA. I have studied some programming before so have a slight idea on syntax , operators etc.

99% of my job I don't need to use VBA but I'm working on something and need to in this case.

In Excel , I have a pricelist which we create a PDF version to send to customer. Up to now this was done manually (using the steps bel0w) but I want to add a button that does it in a single click. I was very lucky that I found some code online which works 99.9% perfectly for me. The 0.1% is that I would like to be able to create 2 pages per sheet rather than the default 1.

Manually this is done by File > Print > Printer (Select ADOBE PDF) > Printer Properties > Layout > Pages Per Sheet = 2

I've spent 2 hours googling on how I can add something to my code but it seems such a function does not exist. I've added the code I'm using below. I would be very grateful if someone can advise me on how I can write a code that will do the > Pages Per Sheet = 2.

I imagine it is just a single line of code to add to the below if such a thing is possible in VBA.

Many thanks!!!

Sub PDFActiveSheet()
'www.contextures.com
'for Excel 2010 and later
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "yyyymmdd\_hhmm")
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & ""
'replace spaces and periods in sheet name
' strName = Replace(wsA.Name, " ", "")
strName = Range("R10")
strName = Replace(strName, ".", "_")
'create default name for savng file
strFile = strName & "_" & strTime & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")


'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True


'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,215,159
Messages
6,123,351
Members
449,097
Latest member
thnirmitha

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