'Devan Munn '4/28/17 Private Sub UserForm_Initialize() OptionButton_BW.Value = False OptionButton_Color.Value = True OptionButton_All.Value = False OptionButton_Sel.Value = True OptionButton_Cur.Value = False CheckBox_Foot.Value = False CheckBox_Save.Value = False Label_Printer.Caption = Application.ActivePrinter Label_PDF_Printer.Caption = "Microsoft XPS Document Writer on Ne01:" TextBox_Loc.Value = Environ("USERPROFILE") & "\My Documents\PDF Temp" End Sub Private Sub CommandButton_Cancel_Click() Unload Me End Sub Private Sub CommandButton_PDF_Click() Dim shtName As String Dim n As Integer Dim i As Integer Dim j As Integer Dim SheetArray() As Variant Dim WS As Object Dim temp As String Dim PDF_Name As String On Error Resume Next Application.ActivePrinter = Label_PDF_Printer.Caption 'Store the current sheet name, to return after execution shtName = ActiveSheet.Name PDF_Name = TextBox_Loc.Value & "\" & ActiveWorkbook.Name & " " & Format(Now(), "hms") & ".pdf" If CheckBox_Save.Value = True Then ActiveWorkbook.Save End If 'If the Temporary PDF directory doesn't exist, then creat it If Dir(TextBox_Loc.Value, vbDirectory) = Empty Then MkDir (TextBox_Loc.Value) End If n = 1 j = 0 'Print all visible worksheets If OptionButton_All.Value = True Then For i = 1 To ActiveWorkbook.Sheets.Count If Sheets(i).Visible = True And IsEmpty(Sheets(i).UsedRange) = False Then ReDim Preserve SheetArray(j) SheetArray(j) = i j = j + 1 End If Next i Sheets(SheetArray).Select For Each WS In ActiveWindow.SelectedSheets With WS.PageSetup .PaperSize = xlPaperLetter .BlackAndWhite = OptionButton_BW.Value .FitToPagesWide = 1 .Zoom = False End With If CheckBox_Foot.Value = True Then With WS.PageSetup .LeftFooter = ActiveWorkbook.FullName .FooterMargin = Application.InchesToPoints(0) End With End If Next WS Sheets(SheetArray).Select 'TextBox_Loc.Value & "\" & ActiveWorkbook.Name & ".pdf" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_Name, _ Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True 'Print only the current worksheet ElseIf OptionButton_Cur.Value = True Then Sheets(ActiveSheet.Name).Select With ActiveSheet.PageSetup .PaperSize = xlPaperLetter .BlackAndWhite = OptionButton_BW.Value .FitToPagesWide = 1 .Zoom = False End With If CheckBox_Foot.Value = True Then With ActiveSheet.PageSetup .LeftFooter = ActiveWorkbook.FullName .FooterMargin = Application.InchesToPoints(0) End With End If ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_Name, _ Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True 'Print all selected worksheets ElseIf OptionButton_Sel.Value = True Then For Each WS In ActiveWindow.SelectedSheets With WS.PageSetup .PaperSize = xlPaperLetter .BlackAndWhite = OptionButton_BW.Value .FitToPagesWide = 1 .Zoom = False End With If CheckBox_Foot.Value = True Then With WS.PageSetup .LeftFooter = ActiveWorkbook.FullName .FooterMargin = Application.InchesToPoints(0) End With End If Next WS For Each WS In ActiveWindow.SelectedSheets WS.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_Name, _ Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True Exit For Next WS End If If CheckBox_Foot.Value = True Then Call Remove_HeaderFooter End If Sheets(shtName).Select Application.ActivePrinter = Label_Printer.Caption Unload Me End Sub Private Sub Remove_HeaderFooter() 'http://www.ozgrid.com/forum/showthread.php?t=165794 Dim WS As Object Application.ScreenUpdating = False For Each WS In ActiveWindow.SelectedSheets With WS.PageSetup .CenterFooter = "" .LeftFooter = "" .RightFooter = "" End With Next WS Application.ScreenUpdating = True End Sub