PDA

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



rafi_07max
11-22-2010, 07:21 AM
I want open a .txt file.

take a look at the image below first:
http://www.iimmgg.com/image/cdb6da96a0b381f60d7c9ae6d767943a

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.
4960

nst1107
11-23-2010, 01:20 PM
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.

rafi_07max
11-23-2010, 08:31 PM
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

Workbooks.OpenText Filename:=TextBox1.Text + "\" + ComboBox1.Value + ".txt", _
DataType:=xlDelimited, Tab:=True