Created
December 5, 2025 18:33
-
-
Save pedroinfo/0282c190ea8a633049b2ae65f8d49887 to your computer and use it in GitHub Desktop.
JsonExcel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub PreencherSheet2(json As Object) | |
| Dim ws As Worksheet | |
| Set ws = ThisWorkbook.Sheets("Sheet2") | |
| ' Limpa a sheet toda | |
| ws.Cells.Clear | |
| ' JSON deve ser um array de objetos | |
| If json.Count = 0 Then Exit Sub | |
| Dim first As Object | |
| Set first = json(1) | |
| Dim key As Variant | |
| Dim col As Long: col = 1 | |
| ' === Cabeçalho === | |
| For Each key In first.Keys | |
| With ws.Cells(1, col) | |
| .Value = key | |
| .Font.Bold = True ' negrito | |
| End With | |
| col = col + 1 | |
| Next key | |
| ' === Preencher dados === | |
| Dim row As Long: row = 2 | |
| Dim item As Object | |
| For Each item In json | |
| col = 1 | |
| For Each key In first.Keys | |
| ws.Cells(row, col).Value = item(key) | |
| col = col + 1 | |
| Next key | |
| row = row + 1 | |
| Next item | |
| ' Ajusta colunas | |
| ws.Columns.AutoFit | |
| ' Ativar AutoFiltro | |
| ws.Rows(1).AutoFilter | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment