Prezados, boa tarde.
Estou com um problema: Elaborei uma macro que busca informações (empresariais, portanto, sigilosas) em duas planilhas. Porém, existe a possibilidade de, esporadicamente, uma ou ambas as planilhas serem movidas de lugar.
A questão é: É possível criar uma macro que busque informações em planilhas mas, quando não encontradas (Ex.: endereço inválido) a macro passe para a próxima planilha e, se ambas não forem encontradas, a macro se encerre?
NOTA: Se ambas as planilhas estiverem nos endereços corretos, traz informações das duas.
Exemplo:
Workbooks.Open Filename:= _
[b] "H:Ger_AdmFinFinanceiroTesouraria4 - Sistema RecebimentosContenciosoCobrançaRepresentantes201754 - GENARIEnvio1.XLSX"[/b]
Range("A1:U1").Select
Selection.AutoFilter
Range("A1").Select
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Plan1").Select
Sheets("Plan1").Name = "Retorno Relatório de Cobrança"
Cells.Select
ActiveWindow.DisplayGridlines = False
Windows("MODELO.xlsm").Activate
Sheets("Retorno").Select
Selection.Copy
Windows("1.XLSX").Activate
ActiveSheet.Paste
ActiveSheet.Paste
Selection.Replace What:="[MODELO.xlsm]", Replacement:="", LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets("Sheet1").Select
ActiveSheet.Range("$A$1:$U$248").AutoFilter Field:=4, Criteria1:="<>"
Range("D2:D300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Retorno Relatório de Cobrança").Select
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells.Select
Application.CutCopyMode = False
Selection.Locked = False
Selection.FormulaHidden = False
Range("B4:D407").Select
Range("A1:K4,A5:H407").Select
Range("E4").Activate
Selection.Locked = True
Range("B4:L4").Select
Application.CutCopyMode = False
Selection.AutoFilter
ActiveSheet.Range("$B$4:$L$407").AutoFilter Field:=1, Criteria1:="<>"
Range("A1").Select
Selection.FormulaHidden = False
ActiveSheet.Protect "453216", AllowFormattingColumns:=True, AllowFormattingRows:=True
Range("A1").Select
ActiveWindow.Zoom = 90
Range("M5").Select
ActiveWindow.Zoom = 90
ActiveWindow.FreezePanes = True
Range("A1").Select
ActiveWindow.Zoom = 90
Range("A1").Select
Sheets("Sheet1").Select
ActiveSheet.Range("$A$1:$U$248").AutoFilter Field:=4
Range("A1").Select
ActiveWorkbook.Save
ActiveWindow.Close
Workbooks.Open Filename:= _
[b]"H:Ger_AdmFinFinanceiroTesouraria4 - Sistema RecebimentosContenciosoCobrançaRepresentantes201754 - GENARIEnvio2.XLSX"[/b]
Range("A1:U1").Select
Selection.AutoFilter
Range("A1").Select
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Plan1").Select
Sheets("Plan1").Name = "Retorno Relatório de Cobrança"
Cells.Select
ActiveWindow.DisplayGridlines = False
Windows("MODELO.xlsm").Activate
Sheets("Retorno").Select
Selection.Copy
Windows("2.XLSX").Activate
ActiveSheet.Paste
ActiveSheet.Paste
Selection.Replace What:="[MODELO.xlsm]", Replacement:="", LookAt:=xlPart _
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets("Sheet1").Select
ActiveSheet.Range("$A$1:$U$248").AutoFilter Field:=4, Criteria1:="<>"
Range("D2:D300").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Retorno Relatório de Cobrança").Select
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Cells.Select
Application.CutCopyMode = False
Selection.Locked = False
Selection.FormulaHidden = False
Range("B4:D407").Select
Range("A1:K4,A5:H407").Select
Range("E4").Activate
Selection.Locked = True
Range("B4:L4").Select
Application.CutCopyMode = False
Selection.AutoFilter
ActiveSheet.Range("$B$4:$L$407").AutoFilter Field:=1, Criteria1:="<>"
Range("A1").Select
Selection.FormulaHidden = False
ActiveSheet.Protect "453216", AllowFormattingColumns:=True, AllowFormattingRows:=True
Range("A1").Select
ActiveWindow.Zoom = 90
Range("M5").Select
ActiveWindow.Zoom = 90
ActiveWindow.FreezePanes = True
Range("A1").Select
ActiveWindow.Zoom = 90
Range("A1").Select
Sheets("Sheet1").Select
ActiveSheet.Range("$A$1:$U$248").AutoFilter Field:=4
Range("A1").Select
ActiveWorkbook.Save
ActiveWindow.Close
Sheets("Macro").Select
End Sub
Desde já, agradeço a ajuda e disposição dos prezados.
Att.,
Walter J. Feo Jr.
Postado : 10/05/2017 1:46 pm