Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default 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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default 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?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default 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?




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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?



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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?





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.GetOpenFilename vs Application.Dialogs(xlDialogsOpen) Paul Martin Excel Programming 5 August 5th 05 04:44 PM
Application.GetOpenFilename Nigel Excel Programming 0 March 23rd 05 03:24 PM
Application.GetOpenFilename Greg[_19_] Excel Programming 3 February 20th 05 01:55 AM
Application.GetOpenFilename Philipp Oberleitner[_2_] Excel Programming 2 July 9th 04 07:29 PM
Application.GetOpenFileName ptrowe Excel Programming 2 September 11th 03 12:54 PM


All times are GMT +1. The time now is 05:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"