Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Save to Path & Variable file name

Excel 2002, WinXP
When I know the file name, the following code works just fine:
ActiveWorkbook.SaveCopyAs ("C:\Folder1\Folder2\Folder3\MyFile.xls")

I now need to do the same thing but with a variable file name, say
VariableFileName (includes ".xls").
My problem is that I can't get the syntax right.
How do write the above line of code if the file name is a variable? Thanks
for your help. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Save to Path & Variable file name

Chip
I've done that in the past and ended up saving the copy in some folder I
didn't want. That's why I specified the folder path. That brings up
another question. How do I set the current (default?) folder path so that
if I do what you said, the file would be saved in that folder? Thanks for
your help. Otto
"Chip Pearson" wrote in message
...
Otto,

If VarName contains the complete file name, just use something
like

ActiveWorkbook.SaveCopyAs VarName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
When I know the file name, the following code works just fine:
ActiveWorkbook.SaveCopyAs

("C:\Folder1\Folder2\Folder3\MyFile.xls")

I now need to do the same thing but with a variable file name,

say
VariableFileName (includes ".xls").
My problem is that I can't get the syntax right.
How do write the above line of code if the file name is a

variable? Thanks
for your help. Otto






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Save to Path & Variable file name

David
Thanks for that and the explanation. Another entry for my HowTo file.
Otto
"David McRitchie" wrote in message
...
Hi Otto,
I presume your were concerned with the double quotes.
The double quotes just enclose a string.
If you separate that string it might be easier to see

dim str as string
str = "C:\Folder1\Folder2\Folder3\MyFile.xls"
activeworkbook.savecopyas(str)

another example.

dim str as string, myfile as string
myfile = "MyFile.xls"
str = "c:\folder1\folder2\folder3\" & myfile
activeworkbook.savecopyas(str)
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
When I know the file name, the following code works just fine:
ActiveWorkbook.SaveCopyAs ("C:\Folder1\Folder2\Folder3\MyFile.xls")

I now need to do the same thing but with a variable file name, say
VariableFileName (includes ".xls").
My problem is that I can't get the syntax right.
How do write the above line of code if the file name is a variable?
Thanks
for your help. Otto







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Save to Path & Variable file name

Otto,

You can use CurDir to return as a string the current default
drive and directory. E.g.,

Dim S As String
S = CurDir

You can use ChDrive and ChDir to change the default drive and
directory. E.g.,

ChDrive "C:"
ChDir "C:\Folder1\Folder2"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Otto Moehrbach" wrote in message
...
Chip
I've done that in the past and ended up saving the copy in

some folder I
didn't want. That's why I specified the folder path. That

brings up
another question. How do I set the current (default?) folder

path so that
if I do what you said, the file would be saved in that folder?

Thanks for
your help. Otto
"Chip Pearson" wrote in message
...
Otto,

If VarName contains the complete file name, just use

something
like

ActiveWorkbook.SaveCopyAs VarName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Otto Moehrbach" wrote in

message
...
Excel 2002, WinXP
When I know the file name, the following code works just

fine:
ActiveWorkbook.SaveCopyAs

("C:\Folder1\Folder2\Folder3\MyFile.xls")

I now need to do the same thing but with a variable file

name,
say
VariableFileName (includes ".xls").
My problem is that I can't get the syntax right.
How do write the above line of code if the file name is a

variable? Thanks
for your help. Otto








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Save to Path & Variable file name

Thanks Chip, that simplifies things. Otto
"Chip Pearson" wrote in message
...
Otto,

You can use CurDir to return as a string the current default
drive and directory. E.g.,

Dim S As String
S = CurDir

You can use ChDrive and ChDir to change the default drive and
directory. E.g.,

ChDrive "C:"
ChDir "C:\Folder1\Folder2"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Otto Moehrbach" wrote in message
...
Chip
I've done that in the past and ended up saving the copy in

some folder I
didn't want. That's why I specified the folder path. That

brings up
another question. How do I set the current (default?) folder

path so that
if I do what you said, the file would be saved in that folder?

Thanks for
your help. Otto
"Chip Pearson" wrote in message
...
Otto,

If VarName contains the complete file name, just use

something
like

ActiveWorkbook.SaveCopyAs VarName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Otto Moehrbach" wrote in

message
...
Excel 2002, WinXP
When I know the file name, the following code works just

fine:
ActiveWorkbook.SaveCopyAs
("C:\Folder1\Folder2\Folder3\MyFile.xls")

I now need to do the same thing but with a variable file

name,
say
VariableFileName (includes ".xls").
My problem is that I can't get the syntax right.
How do write the above line of code if the file name is a
variable? Thanks
for your help. Otto










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
change default file path in Save As dialog box charles[_2_] Excel Programming 3 August 6th 04 03:03 AM
get path - save new file - same sub-directory as existing file tegger Excel Programming 2 October 21st 03 10:45 AM
Naming a variable in a file path Ron[_13_] Excel Programming 1 October 19th 03 02:56 AM
Using a variable string in a file save path Ron[_13_] Excel Programming 1 October 16th 03 08:29 PM
Save file path in cell Jim Melchers Excel Programming 1 September 19th 03 11:36 PM


All times are GMT +1. The time now is 10:50 PM.

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"