Livre para escolher o local onde se encontra o arquivo txt
Enviado: 18 Dez 2017 às 17:58
Boa noite galera. Tudo bem?
Estou precisando de um pouquinho de ajuda.
Gravei uma macro, importando e tabulando um arquivo txt, tudo certo, mas preciso que seja possível selecionar o local e o arquivo que será importado. Um arquivo fixo em um caminho fixo, foi fácil. rs
Segue abaixo como fiz a macro e onde esta o arquivo, por favor, como consigo abrir um formulário, pedindo o local e o arquivo que deverá ser importado? Claro, seguindo a parte de tabulação.
Segue abaixo parte da macro
Sub Macro1()
'
' Macro1 Macro
'
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Z:\CONTABILIDADE\#Projeto\2013\bonde.txt" , Destination:=Range("$A$1"))
' .CommandType = 0
.Name ="bonde"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

Estou precisando de um pouquinho de ajuda.
Gravei uma macro, importando e tabulando um arquivo txt, tudo certo, mas preciso que seja possível selecionar o local e o arquivo que será importado. Um arquivo fixo em um caminho fixo, foi fácil. rs
Segue abaixo como fiz a macro e onde esta o arquivo, por favor, como consigo abrir um formulário, pedindo o local e o arquivo que deverá ser importado? Claro, seguindo a parte de tabulação.
Segue abaixo parte da macro
Sub Macro1()
'
' Macro1 Macro
'
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Z:\CONTABILIDADE\#Projeto\2013\bonde.txt" , Destination:=Range("$A$1"))
' .CommandType = 0
.Name ="bonde"

.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
