View Full Version : VBA Print to PDF Button code issues with multiple users

Phil Lees
03-14-2017, 10:28 AM
Hello, I'm hoping somebody can help me with this, the code below allows users to print to pdf by clicking a button, but depending on the user, it may or may not work. I have concluded that the "NE" number is to blame, and that it's different between users. Can I alter the code to make it scan through "NE01" onwards, to make sure that this code works for everyone? I thought this code did that anyway, but appears as though it doesn't.

Thanks in advance.

Sub CommandButton2_Click()

ActiveSheet.PageSetup.RightHeader = Format(Now, "MMMM DD, YYYY")

PrtOK = True

Dim Msg As String
Dim C As Integer
Dim PrinterName As String

C = 1

On Error GoTo MakePDFError:

If C < 10 Then
PrinterName = "Adobe PDF on Ne0" & C & ":"
PrinterName = "Adobe PDF on Ne" & C & ":"
End If

Application.ActivePrinter = PrinterName
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF on Ne04:", collate:=True

Exit Sub

C = C + 1
Resume ResumePrinting:
End Sub

03-14-2017, 10:44 AM
Have you tried the built-in pdf?

Recorded macro

Sub Macro7()
ChDir "C:\Users\Emachine\Downloads"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Emachine\Downloads\Daily List V2.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
End Sub

03-14-2017, 10:50 AM
As an alternative; (not so simple)