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.
I've tried using
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.
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
Any help or direction would be greatly appreciated.