Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Application.GetOpenFilename vs Application.Dialogs(xlDialogsOpen) | Excel Programming | |||
Application.GetOpenFilename | Excel Programming | |||
Application.GetOpenFilename | Excel Programming | |||
Application.GetOpenFilename | Excel Programming | |||
Application.GetOpenFileName | Excel Programming |