How can I get my print to PDF button print to normal page without selected printer?

ArnMan

Board Regular
Joined
Aug 30, 2017
Messages
69
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,

I have a button that prints a Set print area, and exports it to a pdf in the same folder as the excel workbook. I use a label printer as well as a normal printer. When I click the button, it for some reason or another wants to use the current printer settings to make the pdf.

If I can remember beforehand, I would go to my Print section and select the normal printer, and then click the button. And it makes my pdf of the active worksheet normally.
If the label printer is selected, it will attempt to make a pdf based on the tiny labels, with tons of mini pages.

I've tried to search for a way to add a custom page size, just normal 8 1/2 by 11 paper size, multiple pages is fine. I saw a couple of places, where I would have to build the custom size from all kinds of margins, but was unsure what all was needed to make it automatically save at 8 1/2 by 11.
So what I want the button to do is
Click it,
it will take the Print Area and make a pdf without opening up, (set openafterpublish to false so it wouldn't), and save the pdf to the folder of the excel sheet, without using whatever printer is currently selected in the Print section.

But here is my code that I use.


VBA Code:
Private Sub PrintPDF_Click()
Dim fname As Range
Dim foundleft As Range
Dim StrPath As String

StrPath = ActiveWorkbook.Path & "\"
Set fname = Range("B2")
Set foundleft = Range("E6")
If foundleft.Value = "As Found / As Left" Or foundleft.Value = "As Found" Then


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=StrPath & fname.Value & " AF" & " inH2O", Quality:=xlQualityStandard, _
  IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
 
  Else
 
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=StrPath & fname.Value & " AL" & " inH2O", Quality:=xlQualityStandard, _
  IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
 
  End If
 


End Sub

I've tried using
Code:
With ActiveSheet.PageSetup
.PaperSize = xlPaperA4
in my above code, but when I change the printer to the label printer it errors out, but works fine on the normal printer.

Any help or direction would be greatly appreciated.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I recommend you use the Macro Recorder. The vba code generated from the Recorder will guide you on how to create what you are trying to accomplish.
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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