Olá pessoal!
Resolvamos mais esta questão quanto a impressão de planilhas, geralmente contendo Dashboards & Scorecards, ou Cockpits, que precisem ser impressas.
Este código imprime as planilhas selecionadas, veja o código do procedimento PrintSelectedsSheets mostrado abaixo.
Sub PrintSelectedSheets (Preview As Boolean)Dim N As LongDim M As LongDim Arr() As StringWith ActiveWindow.SelectedSheetsReDim Arr(1 To .Count)For N = 1 To .CountLet Arr(N) = .Item(N).NameNext NEnd With
Sheets(Arr).PrintOut Preview:=TrueEnd Sub
Como faço para imprimir apenas as pastas não selecionadas?
Sub PrintUnselectedSheets (Preview As Boolean)
Dim WS As Object
Dim N As Long
Dim Arr() As String
Dim K As Long
Dim B As Boolean
ReDim Arr(1 To ActiveWorkbook.Sheets.Count)
For Each WS In ActiveWorkbook.Sheets
Let B = True
With ActiveWindow.SelectedSheets
For N = 1 To .Count
Let B = True
If StrComp(WS.Name, .Item(N).Name, vbTextCompare) = 0 Then
Let B = False
Exit For
End If
Next N
If B = True Then
Let K = K + 1
Let Arr(K) = WS.Name
End If
End With
Next WS
If K > 0 Then
ReDim Preserve Arr(1 To K)
ActiveWorkbook.Sheets(Arr).PrintOut Preview:=Preview
End If
End Sub
Como posso fazer para imprimir todas as Sheets, excluindo as que passar como parâmetro?
PrintSheetsExclude false, "Sheet2", "Sheet4", "Sheet6"
This prints all sheets except Sheet2, Sheet4, and Sheet6. The code is shown below:
Sub PrintSheetsExclude (Preview As Boolean, ParamArray Excludes() As Variant)
Dim Arr() As String
Dim B As Boolean
Dim N As Long
Dim M As Long
Dim K As Long
ReDim Arr(1 To Sheets.Count)
For N = 1 To Sheets.Count
Let B = True
For M = LBound(Excludes) To UBound(Excludes)
If StrComp(Sheets(N).Name, Excludes(M), vbTextCompare) = 0 Then
Let B = False
Exit For
End If
Next M
If B = True Then
Let K = K + 1
Let Arr(K) = Sheets(N).Name
End If
Next N
If K > 0 Then
ReDim Preserve Arr(1 To K)
Sheets(Arr).PrintOut Preview:=Preview
End If
End Sub
Fonte: C Person
Nenhum comentário:
Postar um comentário