bamaisgreat
Well-known Member
- Joined
- Jan 23, 2012
- Messages
- 831
- Office Version
- 365
- Platform
- Windows
As you can tell the code below prints of the sheets that contain data in them. The trouble im having is about half way down there are some print settings that are only working on the active sheet. Im unsure what to replace the active sheet with so it will apply all the printer settings listed to all pages that are needed.
Code:
Sub SaveSpecificToPDF()
Dim PdfFilename As Variant
Dim ws As Worksheet
'Dim TransNO As String
'Dim fName As String
Dim TransRange As String: TransRange = ActiveSheet.Range("B22").Text
'Old code segment
'fName = ActiveSheet.Range("B21").Value
PdfFilename = Application.GetSaveAsFilename( _
InitialFileName:="GGS Transmittal ", _
FileFilter:="PDF, *.pdf", _
Title:="Save As PDF")
For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
'If statements to select number of sheets to print in transmittal
If ActiveWorkbook.Sheets("Transmittal Generator").Range("F3") = IsEmpty("F3") Then
MsgBox "Nothing to print. Verify Transmittal Generator has been properly filled out."
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6", "Trans Sh 7", "Trans Sh 8", "Trans Sh 9", "Trans Sh 10", "Trans Sh 11", "Trans Sh 12")).Visible = xlSheetHidden
Exit Sub
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F17") = IsEmpty("F17") Then
Sheets(Array("Trans Sh 1")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F31") = IsEmpty("F31") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F45") = IsEmpty("F45") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F59") = IsEmpty("F59") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F73") = IsEmpty("F73") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F87") = IsEmpty("F87") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F101") = IsEmpty("F101") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6", "Trans Sh 7")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F115") = IsEmpty("F115") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6", "Trans Sh 7", "Trans Sh 8")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F129") = IsEmpty("F129") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6", "Trans Sh 7", "Trans Sh 8", "Trans Sh 9")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F143") = IsEmpty("F143") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6", "Trans Sh 7", "Trans Sh 8", "Trans Sh 9", "Trans Sh 10")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F157") = IsEmpty("F157") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6", "Trans Sh 7", "Trans Sh 8", "Trans Sh 9", "Trans Sh 10", "Trans Sh 11")).Select
ElseIf ActiveWorkbook.Sheets("Transmittal Generator").Range("F171") = IsEmpty("F171") Then
Sheets(Array("Trans Sh 1", "Trans Sh 2", "Trans Sh 3", "Trans Sh 4", "Trans Sh 5", "Trans Sh 6", "Trans Sh 7", "Trans Sh 8", "Trans Sh 9", "Trans Sh 10", "Trans Sh 11", "Trans Sh 12")).Select
End If
[B]If PdfFilename <> False Then[/B]
[B] ' With ActiveSheet.PageSetup[/B]
[B] ActiveSheet.PageSetup.PrintArea = "$A$1:$K$49"[/B]
[B] .Orientation = xlPortrait[/B]
[B] .PrintArea = "$A$1:$K$49"[/B]
[B] LeftMargin = Application.InchesToPoints(0.25)[/B]
[B] .RightMargin = Application.InchesToPoints(0.25)[/B]
[B] .TopMargin = Application.InchesToPoints(0.5)[/B]
[B] .BottomMargin = Application.InchesToPoints(0.5)[/B]
[B] .HeaderMargin = Application.InchesToPoints(0.5)[/B]
[B] .FooterMargin = Application.InchesToPoints(0.5)[/B]
[B] .CenterHorizontally = True[/B]
[B] .CenterVertically = False[/B]
[B] .Zoom = False[/B]
[B] .FitToPagesTall = 1[/B]
[B] .FitToPagesWide = 1[/B]
[B] .PaperSize = xlPaperLetter[/B]
[B] End With[/B]
[B]ActiveSheet.ExportAsFixedFormat _[/B]
[B] Type:=xlTypePDF, _[/B]
[B] FileName:=PdfFilename, _[/B]
[B] Quality:=xlQualityStandard, _[/B]
[B] IncludeDocProperties:=False, _[/B]
[B] IgnorePrintAreas:=False, _[/B]
[B] From:=1, _[/B]
[B] To:=12, _[/B]
[B] OpenAfterPublish:=True[/B]
End If
For Each ws In ThisWorkbook.Worksheets
If Left(ws.Name, 6) = "Trans " Then
ws.Visible = xlSheetHidden
End If
Next ws
End Sub