Sub importa_texto_nome()
On Error GoTo erro
Dim Pasta As String
Dim Arquivo As String
Dim linha As Double
Dim registro As String
Dim vetor() As String
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Selecione a pasta"
.Show
If .SelectedItems.Count = 0 Then
Exit Sub
Else
Pasta = .SelectedItems(1) & "\"
End If
End With
Range("A:AA").Clear
Application.Cursor = xlWait
Application.ScreenUpdating = False
linha = 1
Arquivo = Dir(Pasta & Arquivo)
Do While Arquivo <> ""
Open Pasta & Arquivo For Input As #1
DoEvents
Do Until EOF(1)
DoEvents
Line Input #1, registro
vetor() = Split(registro, ";") 'Ajustar a quantidade de colunas de acordo com a necessidade
Cells(linha, 1) = vetor(0)
Cells(linha, 2) = vetor(1)
If linha = 1 Then
Cells(linha, 3) = "Arquivo"
Else
Cells(linha, 3) = Arquivo
End If
linha = linha + 1
Loop
Close #1
Arquivo = Dir
Loop
erro:
Application.ScreenUpdating = True
Application.Cursor = xlDefault
If Err.Number = 0 Then
MsgBox "A importação dos arquivos de texto foi concluída."
Else
MsgBox Err.Description, vbCritical
End If
Exit Sub
End Sub
Eventualmente dicas sobre outros programas, Windows e hardware.
sábado, 15 de julho de 2023
Importação de arquivos csv em lote - Excel VBA
Assinar:
Comentários (Atom)
Pesquisar este blog
Quem sou eu
- Kazu
- Administrador de Empresas/Técnico em Processamento de Dados. Microsoft Office User Specialist - Excel Proficient. Pós-graduado em Business Intelligence.