Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
change default file path in Save As dialog box | Excel Programming | |||
get path - save new file - same sub-directory as existing file | Excel Programming | |||
Naming a variable in a file path | Excel Programming | |||
Using a variable string in a file save path | Excel Programming | |||
Save file path in cell | Excel Programming |