I made this simples code, but this create 4 pdfs files, not only one, can you help me?
Sub PrintToPageX()
Worksheets("Anexo Financeiro").Select
Application.ActivePrinter = "Microsoft Print to PDF on Ne02:"
ActiveWindow.SelectedSheets.PrintOut from:=1, to:=4
If Worksheets("Anexo Financeiro").Range("p205") = 1 Then ThisWorkbook.PrintOut from:=5, to:=5
If Worksheets("Anexo Financeiro").Range("n272") = 1 Then ThisWorkbook.PrintOut from:=6, to:=6
ActiveWindow.SelectedSheets.PrintOut from:=7, to:=7
End Sub
Assuming that Worksheets("Anexo Financeiro")
is the same as ActiveWindow.SelectedSheets
which is the same as ThisWorkbook.ActiveSheet
:
I created an If Statement that checks if the document can be printed all together or if it needs to be separated.
Sub PrintToPageX()
Application.ActivePrinter = "Microsoft Print To PDF on Ne02:"
With Worksheets("Anexo Financeiro")
If .Range("p205") = 1 And .Range("n272") = 1 Then
.PrintOut From:=1, To:=7
Else
.PrintOut From:=1, To:=4
If .Range("p205") = 1 Then .PrintOut From:=5, To:=5
If .Range("n272") = 1 Then .PrintOut From:=6, To:=6
.PrintOut From:=7, To:=7
End If
End With
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.