browse to open file open file

Ziggy

Active Member
Joined
Feb 15, 2002
Messages
346
Is there a way I can have my macro run and give me the option to browse for a specific file.

I have my macro setup to import a text file, I want to be able to make it user friendly so I can share it with other users with out having to correct the path in the code each time.

the text file might also be named differently but contains the same data.

Thanks in advance

Ziggy
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I can make the file open code work, but I am having difficulty in putting it in place of the existing code which finds a specific file name on my PC, then goes through the text import wizard and converts it to Excel.

This is just a sample of the code(I don't have the file with me)

Sub fileopen2()
'
' fileopen2 Macro
' Macro recorded 3/21/2002

'
Workbooks.OpenText Filename:="C:My Documentsmytextfile.txt", Origin:=xlWindows _
, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1)
ActiveWorkbook.SaveAs Filename:="C:My Documentsdupes.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub

I want this macro to be portable so I can send it to other users who can just browse for the correct text file on their PC's, instead of correcting the path.

Thanks

Ziggy
 
Upvote 0
Give this a go.....


fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen<> False Then

Workbooks.OpenText fileToOpen, _ Origin:=xlWindows _
, StartRow:=1,

etc.

End If

Hope this helps,

RET79
This message was edited by RET79 on 2002-03-21 14:32
 
Upvote 0
Thanks !!! I got it working at home so it should be ok at work

This is a bonus thanks alot!

Ziggy
 
Upvote 0
Thanks !!! I got it working at home so it should be ok at work

This is a bonus thanks alot!

Ziggy
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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