Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
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
Filenames and formulae SimoninParis Excel Worksheet Functions 4 September 25th 09 04:21 PM
what do 'blue filenames' mean? Boswell Excel Discussion (Misc queries) 2 January 16th 07 05:36 PM
Using cell value in filenames Neil Beddell Excel Worksheet Functions 3 July 19th 06 08:22 PM
Help with filenames and paths. jim9912 Excel Discussion (Misc queries) 2 March 30th 06 05:52 PM
Using Variables in filenames Blinky Bill Excel Discussion (Misc queries) 2 March 11th 05 12:07 AM


All times are GMT +1. The time now is 03:04 AM.

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"