how to let user select filename when using macro

joed

Board Regular
Joined
May 5, 2002
Messages
50
I have created a macro to open a text file and set the columns,widthes,types etc. It works fine except it always opens the same file.
How do I make it so the user can select the file name to open. Currently it only opens the one file name used when I created the macro. Is there some sort of pause command I can insert into the macro?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
On 2002-05-07 11:13, joed wrote:
I have created a macro to open a text file and set the columns,widthes,types etc. It works fine except it always opens the same file.
How do I make it so the user can select the file name to open. Currently it only opens the one file name used when I created the macro. Is there some sort of pause command I can insert into the macro?

How about the GetOpenFileName method. Look under Help.
 
Upvote 0
I got some help with something along those lines a little while back.

Try adding this to your code instead of opening the one file:<pre>
Which = Application.GetOpenFilename(MultiSelect:=True)
'Which now contains an array of file names which you can enumerate through
For I = 1 To UBound(Which)
Workbooks.Open Which(I)</pre>


This is what worked for me when I wanted it to bring up the open dialog box and let someone choose
the files they want to open.

Hope this helps,

_________________<font color=red>~*</font><font color=blue>Kristy</font><font color=red>*~</font>

"Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane mittam."
WebX

This message was edited by Von Pookie on 2002-05-07 11:27
 
Upvote 0
On 2002-05-07 11:13, joed wrote:
I have created a macro to open a text file and set the columns,widthes,types etc. It works fine except it always opens the same file.
How do I make it so the user can select the file name to open. Currently it only opens the one file name used when I created the macro. Is there some sort of pause command I can insert into the macro?

<pre/>
dim FileName as String
FileName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
</pre>
 
Upvote 0
how would I insert that code into this?

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 05/07/2002 by joe
'

'
Workbooks.OpenText FileName:="T:Mcdrpswg01
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top