ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   add browser menu in excel (https://www.excelbanter.com/excel-discussion-misc-queries/18015-add-browser-menu-excel.html)

scottish_warrior

add browser menu in excel
 
I have a spread sheet that reads data in from a text file before I use it.
Just now I have the user add the text file pathname in a cell and I use that
pathname. I would like to add a browser capability where the user can select
the file just like windows explorer.

Can't find anything to do this. Any help is appreciated.

Thanks


Dave Peterson

You could use a little macro and ask the user to select the input file. (Are
you importing the text file via a macro?)

Dim myFileName as variant
myfilename = application.getopenfilename("Text Files, *.txt")
if myfilename = false then
exit sub 'user hit cancel
end if

'then open that myFilename

I like to record a macro to get all the parms/columns correct.

My line of recorded code looks like:

Workbooks.OpenText Filename:="C:\My Documents\excel\Edit3.txt", _
Origin:=437, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(13, 1), _
Array(20, 1), Array(27, 1), Array(33, 1), Array(39, 1))

Your recorded code would look different.

But then you could modify that recorded code to use the filename specified by
the user:

Workbooks.OpenText Filename:=myFileName, _
Origin:=437, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(13, 1), _
Array(20, 1), Array(27, 1), Array(33, 1), Array(39, 1))

And continue with the rest of your code.

scottish_warrior wrote:

I have a spread sheet that reads data in from a text file before I use it.
Just now I have the user add the text file pathname in a cell and I use that
pathname. I would like to add a browser capability where the user can select
the file just like windows explorer.

Can't find anything to do this. Any help is appreciated.

Thanks


--

Dave Peterson

scottish_warrior

Thanks,

Works perfectly. I already was importing the file via a macro just couldn't
find a way to graphically select the file.

Thanks again.

"Dave Peterson" wrote:

You could use a little macro and ask the user to select the input file. (Are
you importing the text file via a macro?)

Dim myFileName as variant
myfilename = application.getopenfilename("Text Files, *.txt")
if myfilename = false then
exit sub 'user hit cancel
end if

'then open that myFilename

I like to record a macro to get all the parms/columns correct.

My line of recorded code looks like:

Workbooks.OpenText Filename:="C:\My Documents\excel\Edit3.txt", _
Origin:=437, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(13, 1), _
Array(20, 1), Array(27, 1), Array(33, 1), Array(39, 1))

Your recorded code would look different.

But then you could modify that recorded code to use the filename specified by
the user:

Workbooks.OpenText Filename:=myFileName, _
Origin:=437, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(13, 1), _
Array(20, 1), Array(27, 1), Array(33, 1), Array(39, 1))

And continue with the rest of your code.

scottish_warrior wrote:

I have a spread sheet that reads data in from a text file before I use it.
Just now I have the user add the text file pathname in a cell and I use that
pathname. I would like to add a browser capability where the user can select
the file just like windows explorer.

Can't find anything to do this. Any help is appreciated.

Thanks


--

Dave Peterson



All times are GMT +1. The time now is 04:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com