Descricao: |
Escola Saberexcel VBA Estudos® - Treinamento com Macros, Fórmulas e Funções:
 Esse macro relaciona todas as planilhas em todos os livros abertos mesmo a planilha estiver com os códigos vba protegidos, relacionará todas as planilhas existente em um novo livro, isto é: todas folhas de planiha de todos os livros abertos. e o total de linhas usadas na coluna(c) em todas as folhas de planilhas dos livros abertos.
' - - - - - - - - - - - - - - - - Sub RELACIONAR_PLANILHAS_LIVROS_ABERTOS() Dim LinCol As Long, lr As Long, lr2 As Long Dim c As Range, vNovoLivro As Workbook, r As Range Dim vDir As String, sh As Worksheet, wb As Workbook
Set vNovoLivro = Workbooks.Add
For Each wb In Application.Workbooks If wb.Name <> vNovoLivro.Name Then
For Each sh In wb.Worksheets LinCol = 0 lr = Saber1.Cells(Rows.Count, 3).End(xlUp).Row
'- - - - - -' verifica existencia palavra saberexcel '- - - - -' Set c = sh.Cells.Find("Saberexcel", LookIn:=xlValues) ' Set c = Cells.Find("Saberexcel", LookIn:=xlValues) 'mostra somente da planiha ativa If Not c Is Nothing Then Set r = sh.Range("C" & c.Row + 1 & ":C" & lr) LinCol = r.Rows.Count pe = r.Address End If
'var lr2 para o novo livro criado: Primeira planilha(1) With vNovoLivro.Sheets(1) lr2 = vNovoLivro.Sheets(1) _ .Cells(Rows.Count, 1).End(xlUp).Row
'ajustando o tamanho da coluna(A) .Columns("A:C").AutoFit
'inserindo um cabeçalho na nova planiha .Range("A1").Value = "NOME DO ARQUIVO" .Range("B1").Value = "NOME DA FOLHA PLANILHA" .Range("C1").Value = "LINHAS USADAS"
If .Range("A2") = "" Then .Range("A2") = wb.Name .Range("B2") = sh.Name .Range("C2") = LinCol Else .Range("A" & lr2 + 1) = wb.Name .Range("B" & lr2 + 1) = sh.Name .Range("C" & lr2 + 1) = LinCol End If
End With Next End If Next
End Sub
 Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.

|