ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Application.GetOpenFileName (https://www.excelbanter.com/excel-programming/370774-application-getopenfilename.html)

Chris

Application.GetOpenFileName
 
When I type this line into the beginning of my macro and then run the macro,
I am prompted with a file open dialog box. When I select the file to be
opened and click ok, the dialog box goes away and my file is not opened. Is
there more code that I have to add to the macro?

NickHK[_3_]

Application.GetOpenFileName
 
That statement only return the file path/name to you.
It's then up to you what you do with it.

Dim retVal as Variant
dim WB as workbook
retval=application.getopenfilename()
if retval=false then exit sub
set wb=workbooks.open(retval)
....etc

NickHK

"Chris" ...
When I type this line into the beginning of my macro and then run the
macro,
I am prompted with a file open dialog box. When I select the file to be
opened and click ok, the dialog box goes away and my file is not opened.
Is
there more code that I have to add to the macro?




Tom Ogilvy

Application.GetOpenFileName
 
Dim fname as String, bk as Workbook
fname = Application.GetOpenfilename()
if fname < "False" then
set bk = Workbooks.Open(fname)
else
exit sub
end if
msgbox bk.name & " has been opened"

--
Regards,
Tom Ogilvy


"Chris" wrote:

When I type this line into the beginning of my macro and then run the macro,
I am prompted with a file open dialog box. When I select the file to be
opened and click ok, the dialog box goes away and my file is not opened. Is
there more code that I have to add to the macro?


Chris

Application.GetOpenFileName
 
Thanks that worked, but I have one more issue. I would like Excel to prompt
me with the text import wizzard if need be because my files need to be
delimited with certain characters or my macro will not work. So after the
user selects the file to be opened, a text import wizard box pops up asking
about delimited or fixed width options. Is there a way to do this?

"Tom Ogilvy" wrote:

Dim fname as String, bk as Workbook
fname = Application.GetOpenfilename()
if fname < "False" then
set bk = Workbooks.Open(fname)
else
exit sub
end if
msgbox bk.name & " has been opened"

--
Regards,
Tom Ogilvy


"Chris" wrote:

When I type this line into the beginning of my macro and then run the macro,
I am prompted with a file open dialog box. When I select the file to be
opened and click ok, the dialog box goes away and my file is not opened. Is
there more code that I have to add to the macro?


NickHK[_3_]

Application.GetOpenFileName
 
If you recorrd a macro whilst you use the text import, the code generated
will manage the import.
You just need to substitute the filename returned from your .GetOpenFilename
call.

Also, look at the help for the arguments of GetOpenFilename, because you can
supply a file filter to only .txt or .csv or whatever you use.

NickHK

"Chris" ...
Thanks that worked, but I have one more issue. I would like Excel to
prompt
me with the text import wizzard if need be because my files need to be
delimited with certain characters or my macro will not work. So after the
user selects the file to be opened, a text import wizard box pops up
asking
about delimited or fixed width options. Is there a way to do this?

"Tom Ogilvy" wrote:

Dim fname as String, bk as Workbook
fname = Application.GetOpenfilename()
if fname < "False" then
set bk = Workbooks.Open(fname)
else
exit sub
end if
msgbox bk.name & " has been opened"

--
Regards,
Tom Ogilvy


"Chris" wrote:

When I type this line into the beginning of my macro and then run the
macro,
I am prompted with a file open dialog box. When I select the file to be
opened and click ok, the dialog box goes away and my file is not
opened. Is
there more code that I have to add to the macro?




Chris

Application.GetOpenFileName
 
Good advice, it worked.

Thanks A lot, really appreciate it.

"NickHK" wrote:

If you recorrd a macro whilst you use the text import, the code generated
will manage the import.
You just need to substitute the filename returned from your .GetOpenFilename
call.

Also, look at the help for the arguments of GetOpenFilename, because you can
supply a file filter to only .txt or .csv or whatever you use.

NickHK

"Chris" ...
Thanks that worked, but I have one more issue. I would like Excel to
prompt
me with the text import wizzard if need be because my files need to be
delimited with certain characters or my macro will not work. So after the
user selects the file to be opened, a text import wizard box pops up
asking
about delimited or fixed width options. Is there a way to do this?

"Tom Ogilvy" wrote:

Dim fname as String, bk as Workbook
fname = Application.GetOpenfilename()
if fname < "False" then
set bk = Workbooks.Open(fname)
else
exit sub
end if
msgbox bk.name & " has been opened"

--
Regards,
Tom Ogilvy


"Chris" wrote:

When I type this line into the beginning of my macro and then run the
macro,
I am prompted with a file open dialog box. When I select the file to be
opened and click ok, the dialog box goes away and my file is not
opened. Is
there more code that I have to add to the macro?





Tom Ogilvy

Application.GetOpenFileName
 
If the file you select is a textfile, you will get the text import wizard.
--
Regards,
Tom Ogilvy


"Chris" wrote in message
...
Thanks that worked, but I have one more issue. I would like Excel to
prompt
me with the text import wizzard if need be because my files need to be
delimited with certain characters or my macro will not work. So after the
user selects the file to be opened, a text import wizard box pops up
asking
about delimited or fixed width options. Is there a way to do this?

"Tom Ogilvy" wrote:

Dim fname as String, bk as Workbook
fname = Application.GetOpenfilename()
if fname < "False" then
set bk = Workbooks.Open(fname)
else
exit sub
end if
msgbox bk.name & " has been opened"

--
Regards,
Tom Ogilvy


"Chris" wrote:

When I type this line into the beginning of my macro and then run the
macro,
I am prompted with a file open dialog box. When I select the file to be
opened and click ok, the dialog box goes away and my file is not
opened. Is
there more code that I have to add to the macro?




Tom Ogilvy

Application.GetOpenFileName
 
Sorry, I was thinking of the Builtin Dialog - disregard.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
If the file you select is a textfile, you will get the text import wizard.
--
Regards,
Tom Ogilvy


"Chris" wrote in message
...
Thanks that worked, but I have one more issue. I would like Excel to
prompt
me with the text import wizzard if need be because my files need to be
delimited with certain characters or my macro will not work. So after
the
user selects the file to be opened, a text import wizard box pops up
asking
about delimited or fixed width options. Is there a way to do this?

"Tom Ogilvy" wrote:

Dim fname as String, bk as Workbook
fname = Application.GetOpenfilename()
if fname < "False" then
set bk = Workbooks.Open(fname)
else
exit sub
end if
msgbox bk.name & " has been opened"

--
Regards,
Tom Ogilvy


"Chris" wrote:

When I type this line into the beginning of my macro and then run the
macro,
I am prompted with a file open dialog box. When I select the file to
be
opened and click ok, the dialog box goes away and my file is not
opened. Is
there more code that I have to add to the macro?







All times are GMT +1. The time now is 03:41 AM.

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