Views

Histats

Vitrine

VBA Excel - Outros modos para imprimir planilhas selecionadas ou não.

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 Long
Dim M As Long
Dim Arr() As String
With ActiveWindow.SelectedSheets
ReDim Arr(1 To .Count)
For N = 1 To .Count
Let Arr(N) = .Item(N).Name
Next N
End With
Sheets(Arr).PrintOut Preview:=True
End 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

Tags: André Luiz Bernardes, Microsoft, MOS, MS, Office, Office 2007, Office 2010, automation, automação, print, various print, simultaneously print, multi print, selected


André Luiz Bernardes
A&A® - Work smart, not hard.

LinkWithinBrazilVBAExcelSpecialist

Related Posts Plugin for WordPress, Blogger...