Consulting

Results 1 to 3 of 3

Thread: Solved: opening a file using textbox and combobox as the destination path and filename

  1. #1

    Solved: opening a file using textbox and combobox as the destination path and filename

    I want open a .txt file.

    take a look at the image below first:
    http://www.iimmgg.com/image/cdb6da96...7c9ae6d767943a

    The testbox value is the path/destination name.
    The combobox value is the file name

    So taking the image above as example, once I click the open File button it should automatically open a file from C:\Users\Admin\Desktop\summary.txt

    The file should be placed in a new sheet

    How should I do this?

    The “select folder” button is to select the destination path and will place it on the textbox. I have already assigned the codes for this button.

    I have attached a sample worksheet and a summary.txt file.
    Attachment 4960

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    I'm at a poor excuse for a public computer and unable to open your attachment, but I can make a few suggestions to point you in the right direction. First, record a macro while you open a text file from within Excel. Read over the code that is recorded and pay attention to the syntax used. You should be able to see a way to borrow that code and write your own macro that is triggered by clicking the open button and substitutes the values of the text box and combo box in place of the file path hard-coded in the recorded macro.

    Another method that may be more concise is to use the Application.GetOpenFilename method. Check into it and see if it fits the bill.

  3. #3
    Thanks nst1107 for your help.
    I did managed to find out the answer with the assist of VBA help
    the codes worked for me is
    [VBA]
    Workbooks.OpenText Filename:=TextBox1.Text + "\" + ComboBox1.Value + ".txt", _
    DataType:=xlDelimited, Tab:=True
    [/VBA]

Posting Permissions

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