Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Variable Filenames
Hello,
I have a macro which incorporates a routine that writes files to a local directory. I use the simple SaveAs Filename script, as follows: ActiveWorkbook.SaveAs Filename:="C:\S&P 500 INDEX.xls", _ FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False Which is fine, if I know the filename that I'm going to use in advance. However, in most of the jobs I'm trying to run, I won't know the file names in advance. These will come from a lookup that the macro performs. Does anyone know how I might generalize the script above to incorporate a variable? I was thinking about declaring a variable, setting it equal to whatever filename it should be, and somehow using that variable to save the file, so: Dim currentfile as String '(or whatever the case may be) currentfile=ActiveCell '(the cell which will contain the filename) But how do I then use this variable 'currentfile' in a SaveAs script? Obviously, if I use "currentfile" it will be saved as "currentfile.xls". Do I simply put this in parentheses, instead? or is there some completely different syntax that I'm missing? Apologies in advance if this is way too elementary a question. Any help is much appreciated!! -Paul ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Variable Filenames
Hi Paul:
Filename:=currentfile assuming the string currentfile includes the .xls extension. No quotes should be used. Regards, Vasant. "Paul Kendall" wrote in message ... Hello, I have a macro which incorporates a routine that writes files to a local directory. I use the simple SaveAs Filename script, as follows: ActiveWorkbook.SaveAs Filename:="C:\S&P 500 INDEX.xls", _ FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False Which is fine, if I know the filename that I'm going to use in advance. However, in most of the jobs I'm trying to run, I won't know the file names in advance. These will come from a lookup that the macro performs. Does anyone know how I might generalize the script above to incorporate a variable? I was thinking about declaring a variable, setting it equal to whatever filename it should be, and somehow using that variable to save the file, so: Dim currentfile as String '(or whatever the case may be) currentfile=ActiveCell '(the cell which will contain the filename) But how do I then use this variable 'currentfile' in a SaveAs script? Obviously, if I use "currentfile" it will be saved as "currentfile.xls". Do I simply put this in parentheses, instead? or is there some completely different syntax that I'm missing? Apologies in advance if this is way too elementary a question. Any help is much appreciated!! -Paul ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Variable Filenames
Thanks!! I appreciate your help.
------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Filenames and formulae | Excel Worksheet Functions | |||
what do 'blue filenames' mean? | Excel Discussion (Misc queries) | |||
Using cell value in filenames | Excel Worksheet Functions | |||
Help with filenames and paths. | Excel Discussion (Misc queries) | |||
Using Variables in filenames | Excel Discussion (Misc queries) |