I have a Excel spreadsheet and I need to generate a txt after applying a filter. My code is:
Sub gsCriarArquivoTxt() On Error GoTo TratarErro Dim lsCaminho As String Dim llArquivo As Long Dim lLinha As String Dim lContador As Long Dim iTotalLinhas As Long Range(Selection, Selection.End(xlDown)).Select'txt file name lsCaminho = InputBox("Caminho e nome do arquivo:", "Caminho do arquivo...", actName) If Dir(lsCaminho) = "" Then llArquivo = FreeFile Open lsCaminho For Output As #llArquivo iTotalLinhas = Cells(Rows.Count, 1).End(xlUp).Row lContador = 1 While lContador <= iTotalLinhas'Print the data in the file Print #llArquivo, Cells(lContador, 1) & "," & _ Cells(lContador, 2) & "," & _ Cells(lContador, 3) & "," & _ Cells(lContador, 4) & "," & _ Cells(lContador, 5) & "," & _ Cells(lContador, 6) & "," & _ Cells(lContador, 7) & "," & _ Cells(lContador, 8) lContador = lContador + 1 Wend MsgBox "File saved in: " & lsCaminho Close #llArquivo Else MsgBox "File already exists!" End IfSair: Exit SubTratarErro: MsgBox "There was an error generating the file " & Err.Description & " - " & Err.Number GoTo SairEnd Sub
My code read and write rows and colums but not find o first row after the header. I have ther error:"There was an error generating the file incompatible types 13"