0

I am using the following code to print 3 Worksheets in PDF. I am wanting to set the order of the WorkSheets - using the Sheets(array as listed in the code. However, when I run the macro, the "CS_PDF" WorkSheet is placed first, not 2nd per the code. I have rearranged the order and "CS_PDF" is still placed first. Also I noticed when the macro is running, a "Publishing" dialog box appears for a few seconds. Other times using this code, I never seen this box appear.

Application.DisplayAlerts = False
Dim FileSelected As String
Dim Path As String
Dim x As String
x = Sheet15.Range("K4").Value
If Sheet16.Range("M38").Value = "20" Then   ''='<>
Else

FileSelected = Application.GetSaveAsFilename(InitialFileName:=x, FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Save PDF as")
    Sheet18.Visible = True 'SOW_PDF
    Sheet7.Visible = True 'CS_PDF
    Sheet12.Visible = True 'CE_PDF
Sheets(Array("SOW_PDF", "CS_PDF", "CE_PDF")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
            x, Quality:=xlQualityStandard, IncludeDocProperties _
            :=True, ignoreprintareas:=False, openafterpublish:=False
    If Not FileSelected <> "False" Then
    Sheet18.Visible = False
    Sheet12.Visible = False
    Sheet7.Visible = False
    Sheets("Set_UP").Select
    Sheet15.Range("A31").Select
        Sheet15.Protect ("1") ''''''''''''''''''Re-Activate
        Exit Sub
    End If
    Sheet18.Visible = False
    Sheet7.Visible = False
    Sheet12.Visible = False
    Sheets("Set_UP").Select
    Sheet15.Range("L23").Value = "1"
    Sheet15.Range("A31").Select
        Sheet15.Protect ("1") ''''''''''''''''''Re-Activate
Application.DisplayAlerts = True
End If
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
BrentJohn
  • 7
  • 3
  • Excel always prints in left to right tab order I think - you may need to re-order the tabs (temporariily) to get a specific order. Eg see https://stackoverflow.com/questions/29061072/print-multiple-excel-sheets-in-a-specific-order – Tim Williams Mar 05 '23 at 17:00
  • Tim, you were correct. I rearranged the WorkSheet order, and it works perfect. Thanks! – BrentJohn Mar 05 '23 at 17:30

0 Answers0