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 WithSheets(Arr).PrintOut Preview:=TrueEnd Sub
Como faço para imprimir apenas as pastas não selecionadas?
Sub PrintUnselectedSheets (Preview As Boolean)Dim WS As ObjectDim N As LongDim Arr() As StringDim K As LongDim B As BooleanReDim Arr(1 To ActiveWorkbook.Sheets.Count)For Each WS In ActiveWorkbook.SheetsLet B = TrueWith ActiveWindow.SelectedSheetsFor N = 1 To .CountLet B = TrueIf StrComp(WS.Name, .Item(N).Name, vbTextCompare) = 0 ThenLet B = FalseExit ForEnd IfNext NIf B = True ThenLet K = K + 1Let Arr(K) = WS.NameEnd IfEnd WithNext WSIf K > 0 ThenReDim Preserve Arr(1 To K)ActiveWorkbook.Sheets(Arr).PrintOut Preview:=PreviewEnd IfEnd 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 StringDim B As BooleanDim N As LongDim M As LongDim K As LongReDim Arr(1 To Sheets.Count)For N = 1 To Sheets.CountLet B = TrueFor M = LBound(Excludes) To UBound(Excludes)If StrComp(Sheets(N).Name, Excludes(M), vbTextCompare) = 0 ThenLet B = FalseExit ForEnd IfNext MIf B = True ThenLet K = K + 1Let Arr(K) = Sheets(N).NameEnd IfNext NIf K > 0 ThenReDim Preserve Arr(1 To K)Sheets(Arr).PrintOut Preview:=PreviewEnd IfEnd 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.