Set Variable On VBA Import Text to Excel

I have this code inside VBA to include .txt file

Sub Import_Text()
    
    Sheets("WS ABCD").Select
    Range("A1").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;D:\DATA NOSTRO\OTOMASI REKON 2023\2. FEBRUARY 2023\17\DATA\7. CITI ABC 170223.txt" _ '---- I Want Change This Code with set Variable On Uipath 
        , Destination:=Range("$A$1"))
        .Name = "7. CITI ABC 170223"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = True
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = True
        .TextFileColumnDataTypes = Array(9, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    
End Sub

Variable On UiPath = GetFile

What should I do?

Hi @samarasenja

Use Invoke VBA activity & provide the file path as the input. Set method entry as Import_Text & run the process.

Hope this helps,
Best Regards.

do I need to change the code in vba too?
Can you help me show the flow?

@samarasenja

As the code looks neat, you can try executing it once. The flow is simple, take the Invoke VBA activity & pass the file path. Since your code is of Sub Import_Text(), the entry method to the VBA activity will be Import_Text.

If you find any challenges on or after execution, let us know.

Best Regards.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.