Results 1 to 5 of 5

how to link userform / ComboBox value to import text file

Threaded View

  1. #1
    Registered User
    Join Date
    01-01-2014
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    26

    how to link userform / ComboBox value to import text file

    Hello Everyone. I am novice and seek your assistance to make more effective macro.

    There are about 80 text files in a folder. Those text files are named P01.txt, P02.txt and so on. Below I have a macro to import data from P39.txt

    However I am looking for more efficient macro to avoid changing file path when I have to import any other file between P01.txt to P99.txt

    I thought one solution would be linking with userform's value. For example on the file I have attached, there is ComboBox which contains value P01 to P99. Is it possible to select value and import txt file? suppose if I select P05 on ComboBox and run the macro - would it be possible to get P05.txt imported on Destination? Hope I have been able to clarify the scenario, but not sure it may work as I wish. Any better suggestion is most welcome.


    Any help would be appreciated.

    Many thanks and regards




    Private Sub sbImportData_Click()
    
    ThisWorkbook.Worksheets("VAR").Cells.Clear
    
    Application.CutCopyMode = False
        With Sheets("VAR").QueryTables.Add(Connection:= _
    "TEXT;C:\Users\Dell\Desktop\VBA workshop\Practice\P39.txt", Destination:=Sheets("VAR").Range("$A$1"))
            .Name = "name_of_file"
            .FieldNames = True
            .AdjustColumnWidth = False
            .TextFileColumnDataTypes = Array(1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        
        
        
        Range("E7").Select
        
        
    End Sub
    Attached Files Attached Files
    Last edited by yogi_himalayan; 01-02-2014 at 05:36 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Link Text box to a column of combobox
    By 555Rage in forum Excel General
    Replies: 0
    Last Post: 09-21-2012, 03:22 AM
  2. [SOLVED] Import text file from VBA code; import all numbers as text
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-19-2012, 05:19 PM
  3. Link text Box to Combobox in Userform and autoupdate database
    By abhiD in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-20-2012, 06:58 AM
  4. Populate a userform combobox from a .txt file
    By ashmott in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2011, 02:24 AM
  5. userform combobox list link to sheets of different name
    By brainfreez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2008, 03:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1