Hoje criei a função abaixo que cria arquivos texto a partir de planilhas do Excel, é interessante para criar arquivos formatados, com delimitadores específicos, sem ter muito trabalho.
Sub gsCriarArquivoTexto() On Error GoTo TratarErro Dim lsCaminho As String Dim llArquivo As Long Dim llLinha As String Dim lContador As Long Dim iTotalLinhas As Integer 'Path where the file will be saved lsCaminho = InputBox("Caminho e nome do arquivo:", "Caminho do aruivo...", ActName) 'Identifies whether the file already exists If Dir(lsCaminho) = "" Then llArquivo = FreeFile Open lsCaminho For Output As #llArquivo Selection.End(xlDown).Select iTotalLinhas = Cells(Rows.Count, 1).End(xlUp).Row While lContador < iTotalLinhas lContador = lContador + 1 'Write data to the file Print #llArquivo, Cells(lContador, 1) & "|" & Cells(lContador, 2) & _ "|" & Cells(lContador, 3) & "|" & Cells(lContador, 4) Wend MsgBox "Arquivo Salvo em: " & lsCaminho 'Close the file Close #llArquivo Else MsgBox "Arquivo já existe!" End If 'Error treatment Sair: Exit Sub TratarErro: MsgBox "There was an error writing the file!" GoTo Sair Resume End Sub
Download Arquivo Texto Delimitado Excel VBA
Realize o download da planilha Excel VBA para gerar arquivo texto no Excel neste botão abaixo. Basta se inscrever na nossa newsletter gratuita para o download automático.