Página 2 de 2

Re: Exportar Arquivo para txt

Enviado: Seg Mai 13, 2019 2:44 pm
por Reinaldo
Experimente:
Substitua

Código: Selecionar todos

FileSaveName = Application.GetSaveAsFilename( _
               InitialFileName:="C:\users" + _
                                VBA.Strings.Format(Now, "mmddyyyy") + ".txt", _
               fileFilter:="Text Files (*.txt), *.txt")

If FileSaveName = False Then Exit Sub
por:

Código: Selecionar todos

FileSaveName = (ActiveWorkbook.Path & "\temp\" & ActiveSheet.Name & " " & Format(Date, "dd-mm-yyyy") & ".txt")

Re: Exportar Arquivo para txt

Enviado: Seg Mai 13, 2019 5:52 pm
por Alex Abreu
Reinaldo escreveu: Seg Mai 13, 2019 2:44 pm Experimente:
Substitua

Código: Selecionar todos

FileSaveName = Application.GetSaveAsFilename( _
               InitialFileName:="C:\users" + _
                                VBA.Strings.Format(Now, "mmddyyyy") + ".txt", _
               fileFilter:="Text Files (*.txt), *.txt")

If FileSaveName = False Then Exit Sub
por:

Código: Selecionar todos

FileSaveName = (ActiveWorkbook.Path & "\temp\" & ActiveSheet.Name & " " & Format(Date, "dd-mm-yyyy") & ".txt")
Opa valeu pela dica Reinaldo, deu certo aqui
Eu até cheguei a achar um outro método que pega célula por célula separando por | para facilitar a importação hehe

Código: Selecionar todos

Sub Exportar_Cadastro()
Dim sCaminho As String
Dim iFF As Integer
Planilha6.Range("B1").Select
sCaminho = (ActiveWorkbook.Path & "\Temp\" & Planilha6.Name & " Usuário " & Planilha7.Range("B4").Value & " " & Format(Date, "dd-mm-yyyy") & ".txt")
On Error GoTo erro_logacesso
iFF = FreeFile
Open sCaminho For Output As iFF
Do While ActiveCell.Value <> ""
Print #1, ActiveCell.Value & "|" & ActiveCell.Offset(0, 1).Value & "|" & ActiveCell.Offset(0, 2).Value & "|" _
& ActiveCell.Offset(0, 3).Value & "|" & ActiveCell.Offset(0, 4).Value & "|" & ActiveCell.Offset(0, 5).Value _
& "|" & ActiveCell.Offset(0, 6).Value & "|" & ActiveCell.Offset(0, 7).Value & "|" & ActiveCell.Offset(0, 8).Value _
& "|" & ActiveCell.Offset(0, 9).Value & "|" & ActiveCell.Offset(0, 10).Value & "|" & ActiveCell.Offset(0, 11).Value _
& "|" & ActiveCell.Offset(0, 12).Value & "|" & ActiveCell.Offset(0, 13).Value & "|" & ActiveCell.Offset(0, 14).Value _
& "|" & ActiveCell.Offset(0, 15).Value & "|" & ActiveCell.Offset(0, 16).Value & "|" & ActiveCell.Offset(0, 17).Value _
& "|" & ActiveCell.Offset(0, 18).Value & "|" & ActiveCell.Offset(0, 19).Value & "|" & ActiveCell.Offset(0, 20).Value, ""
        Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
    Loop
    
    Close iFF
Exit Sub

erro_logacesso:
Close iFF
End Sub
De qualquer forma agora só tenho que descobrir como importar sem deixar o objeto TXT vinculado pois o Setor de Controle Interno necessitará importar esses backups para fazer conferencia, vou ver se acho algo por aqui no fórum antes de criar um tópico novo...

EDIT: Já achei uma maneira de importar e excluir a conexão que a macro capturada pelo menu obter dados externos faz
Caso alguém precisar da macro que limpa todas as conexões de um workbook sem mencionar nomes aqui vai

Código: Selecionar todos

Sub deleteConnections()
 
For i = 1 To ActiveWorkbook.Connections.Count
If ActiveWorkbook.Connections.Count = 0 Then Exit Sub
ActiveWorkbook.Connections.Item(i).Delete
i = i - 1
Next i

End Sub