Importação de arqui...
 
Notifications
Clear all

Importação de arquivo .txt automaticamente.

1 Posts
1 Usuários
0 Likes
862 Visualizações
(@polchera)
Posts: 5
Active Member
Topic starter
 

Como buscar um arquivo .txt para importação no Excel automaticamente, dentro de uma pasta no C:, sem precisar abrir o código VBA para alterar o endereço do arquivo?
Observação: O nome da pasta e do arquivo .txt mudam mensalmente.
Favor alterar no código abaixo com deve ficar.

Segue o código:

Sub Importar_Relatório()
'
' Importar_Relatório Macro
'
' Atalho do teclado: Ctrl+Shift+R
'
    Range("A2").Select
    Rows("2:2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("A3").Select


    Range("A2").Select
    Application.CutCopyMode = False
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:Conciliação da Retenções Federais10-2019Relatório - 10-2019.txt" _
        , Destination:=Range("$A$2"))
        .Name = "Relatório.txt"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 1252
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileOtherDelimiter = ";"
        .TextFileColumnDataTypes = Array(1, 2, 2, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    Rows("2:2").Select
    Selection.RowHeight = 35
    Columns("A:A").ColumnWidth = 14
    Range("A3").Select

End Sub
 
Postado : 05/12/2019 10:20 am