![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Ontario, Canada
Posts: 326
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
Sure, take a look at the
GetOpenFileName method, which returns the filename of the selected file, or False (I think) if canceled. |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Ontario, Canada
Posts: 326
|
Thanks! Thats great I found an example in the help file.
Ziggy |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Ontario, Canada
Posts: 326
|
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 |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Mar 2002
Location: England, UK.
Posts: 526
|
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 ] |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: Ontario, Canada
Posts: 326
|
Thanks !!! I got it working at home so it should be ok at work
This is a bonus thanks alot! Ziggy |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Ontario, Canada
Posts: 326
|
Thanks !!! I got it working at home so it should be ok at work
This is a bonus thanks alot! Ziggy |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|