Archive of Mr Excel Message Board

Back to Excel VBA archive index
Back to archive home

?? on an Archive2 post re: Save file name = contents of a cell
Posted by Lori D on September 24, 2001 5:39 AM
I have a question that I found a partial answer to in Archive2 on how to save a file using the contents of a cell as the file name. My question is, what if the contents of the cell is a date? I am getting an error that I think is due to the "\" in the date? How can I fix this? BTW - The response to the question in the archive was the following code from Alix:
Sub NameFile
Range("A1").Select
file_path = ActiveCell.Value
Thanks in advance for your help.
Range("B1").Select
ActiveWorkbook.SaveAs FileName:=file_path & ActiveCell.Value
End Sub
Cell A1 contains the filepath, B1 contains (what I want to be) the file name.

| Check out our Excel VBA Resources
|
 |
 |
 |
 |
 |
Re: ?? on an Archive2 post re: Save file name = contents of a cell
Posted by Ian on September 24, 2001 5:54 AM
not being the best (by a long way) try:
Sub NameFile
ActiveWorkbook.SaveAs ("C:\" & " " & Range("a1").Value & " " & Format((Range("b1").Value), "dd-mm-yy"))
End Sub
I'm assumig the date is B1, you can change the format of the date to whatever you need (but as you know "\" is not aloud, it's a directory break)
you'll need to change the path to where you want to save it
e.g. C:\my path\my second path
being he folder 'my second path' which can be found in the folder 'my path' on the 'C:' drive
any help??
Ian

Re: ?? on an Archive2 post re: Save file name = contents of a cell
Posted by LoriD on September 24, 2001 6:25 AM
Thanks Ian - worked great!

This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our
online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.