Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Set Location and Filename to replace GetOpenFilename

I currently have code that when the macro is executed, allows the user to
choose the file needed to write data to. I wrote it this way as I will be
sending the file out to multiple locations and cannot control where the user
may place the file. Here is the code that allows the user to choose the
location and filename:

Do
fName = Application.GetOpenFilename
Loop Until fName < False
Set BonusFile = Workbooks.Open(Filename:=fName)

What I would like to do is have the user, on first use of the macro, go to
the location where they initially saved the file and open it, but then have a
message box open and ask the user if they would like to save this path and
filename as the default location and filename.
If they answer yes, the macro would save the specific path to the file and
then specific filename in the macro and have the macro use this path and
filename in the future without the user having to open the file manually
again.
There would probably need to be a trap so that if the file is renamed or
moved after the location is created, the macro would go back to letting the
user once again choose the location and file, but when chosen, would then ask
if the user wants to set the path and filename again.

Can you help with this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Set Location and Filename to replace GetOpenFilename

create a defined name

insert=Name=Define

in the workbook that contains the code.

put the name in that. Then in your code, check if there is a string stored
there that is a valid filename. If so, use that file. If not, then prompt.

After you update the string in the defined name/range, you will need to save
the file.

You can make this name visible = false

--
Regards,
Tom Ogilvy

"David" wrote in message
...
I currently have code that when the macro is executed, allows the user to
choose the file needed to write data to. I wrote it this way as I will be
sending the file out to multiple locations and cannot control where the

user
may place the file. Here is the code that allows the user to choose the
location and filename:

Do
fName = Application.GetOpenFilename
Loop Until fName < False
Set BonusFile = Workbooks.Open(Filename:=fName)

What I would like to do is have the user, on first use of the macro, go to
the location where they initially saved the file and open it, but then

have a
message box open and ask the user if they would like to save this path and
filename as the default location and filename.
If they answer yes, the macro would save the specific path to the file and
then specific filename in the macro and have the macro use this path and
filename in the future without the user having to open the file manually
again.
There would probably need to be a trap so that if the file is renamed or
moved after the location is created, the macro would go back to letting

the
user once again choose the location and file, but when chosen, would then

ask
if the user wants to set the path and filename again.

Can you help with this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Set Location and Filename to replace GetOpenFilename

Yes...that sounds like exactly what I want to do...but as a new user, I'm not
sure of the code involved.....Can you be more specific with the code
required?
Thanks again!

"Tom Ogilvy" wrote:

create a defined name

insert=Name=Define

in the workbook that contains the code.

put the name in that. Then in your code, check if there is a string stored
there that is a valid filename. If so, use that file. If not, then prompt.

After you update the string in the defined name/range, you will need to save
the file.

You can make this name visible = false

--
Regards,
Tom Ogilvy

"David" wrote in message
...
I currently have code that when the macro is executed, allows the user to
choose the file needed to write data to. I wrote it this way as I will be
sending the file out to multiple locations and cannot control where the

user
may place the file. Here is the code that allows the user to choose the
location and filename:

Do
fName = Application.GetOpenFilename
Loop Until fName < False
Set BonusFile = Workbooks.Open(Filename:=fName)

What I would like to do is have the user, on first use of the macro, go to
the location where they initially saved the file and open it, but then

have a
message box open and ask the user if they would like to save this path and
filename as the default location and filename.
If they answer yes, the macro would save the specific path to the file and
then specific filename in the macro and have the macro use this path and
filename in the future without the user having to open the file manually
again.
There would probably need to be a trap so that if the file is renamed or
moved after the location is created, the macro would go back to letting

the
user once again choose the location and file, but when chosen, would then

ask
if the user wants to set the path and filename again.

Can you help with this?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Set Location and Filename to replace GetOpenFilename

Dim sStr as String
Dim BonusFile as Workbook
sStr = ""
On Error Resume Next
sStr = Evaluate(thisworkbook.Names("ABC").RefersTo)
On Error goto 0
if sStr = "" then
Do
fName = Application.GetOpenFilename
Loop Until fName < False
Set BonusFile = Workbooks.Open(Filename:=fName)
ThisWorkbook.Names.Add Name:="ABC", _
RefersTo:="=""" & BonusFile.FullName & """", _
Visible = False
else
set Bonusfile = Workbooks.Open(sStr)
End if

--
Regards,
Tom Ogilvy



"David" wrote in message
...
Yes...that sounds like exactly what I want to do...but as a new user, I'm

not
sure of the code involved.....Can you be more specific with the code
required?
Thanks again!

"Tom Ogilvy" wrote:

create a defined name

insert=Name=Define

in the workbook that contains the code.

put the name in that. Then in your code, check if there is a string

stored
there that is a valid filename. If so, use that file. If not, then

prompt.

After you update the string in the defined name/range, you will need to

save
the file.

You can make this name visible = false

--
Regards,
Tom Ogilvy

"David" wrote in message
...
I currently have code that when the macro is executed, allows the user

to
choose the file needed to write data to. I wrote it this way as I will

be
sending the file out to multiple locations and cannot control where

the
user
may place the file. Here is the code that allows the user to choose

the
location and filename:

Do
fName = Application.GetOpenFilename
Loop Until fName < False
Set BonusFile = Workbooks.Open(Filename:=fName)

What I would like to do is have the user, on first use of the macro, g

o to
the location where they initially saved the file and open it, but then

have a
message box open and ask the user if they would like to save this path

and
filename as the default location and filename.
If they answer yes, the macro would save the specific path to the file

and
then specific filename in the macro and have the macro use this path

and
filename in the future without the user having to open the file

manually
again.
There would probably need to be a trap so that if the file is renamed

or
moved after the location is created, the macro would go back to

letting
the
user once again choose the location and file, but when chosen, would

then
ask
if the user wants to set the path and filename again.

Can you help with this?






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
Using filename retrieved from GetOpenFilename Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 2 September 12th 08 07:47 PM
Separating Location and Filename in a cell Jim Jackson Excel Worksheet Functions 4 December 27th 06 07:27 PM
"the file already exsists in this location do you want to replace. jenn Excel Discussion (Misc queries) 7 October 9th 06 07:19 PM
Formula to replace invalid filename characters tschultz Excel Worksheet Functions 2 January 27th 06 07:07 PM
Find & replace a value in an unknown cell location mellowe Excel Discussion (Misc queries) 2 November 20th 05 09:17 PM


All times are GMT +1. The time now is 09:37 AM.

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

About Us

"It's about Microsoft Excel"