close

Could anyone show me how to create a macro to save a workbook with file name
plus a date taken from a cell in a worksheet. That is quot;filenamequot; quot;datequot;
(where quot;filenamequot; is the name of the workbook and quot;datequot; has been manually
input to a cell in one of the worksheets).

thanks

Let's say that A1 thru A3 contain:
C:\sample
1_25_2006
..xls
and in A4 we put the formula
=A1 amp; A2 amp; A3
in A4 then we will see:
C:\sample1_25_2006.xlsin this simple example a2 will be updated with new dates

Then enter and run this tiny macro:Sub Macro1()
Dim s As String
s = Cells(4, 1)
ActiveWorkbook.SaveAs Filename:= _
s, FileFormat:= _
xlNormal, Password:=quot;quot;, WriteResPassword:=quot;quot;,
ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub

--
Gary's Studentquot;Bill Kirkquot; wrote:

gt; Could anyone show me how to create a macro to save a workbook with file name
gt; plus a date taken from a cell in a worksheet. That is quot;filenamequot; quot;datequot;
gt; (where quot;filenamequot; is the name of the workbook and quot;datequot; has been manually
gt; input to a cell in one of the worksheets).
gt;
gt; thanks
gt;


This macro assumes that the date you want appended to the file name
exists in a named range (DateRange) on Sheet1.

If the original filename was -Book1.xls -and the DateRange had 1/25/06,
the resulting filename would be -Book1_01-25-2006.xls-Sub AppendDateToFilename()

Dim strDate As String
Dim strFullName As String

'Saves the file in the same directory with the text (date) from Sheet
quot;Sheet1quot; Rangename quot;DateRangequot; appended to the original filename
strDate = Format(Worksheets(quot;Sheet1quot;).Range(quot;DateRangequot;),
quot;mm-dd-yyyyquot;)
strFullName = Left(ActiveWorkbook.FullName,
Len(ActiveWorkbook.FullName) - 4) amp; quot;_quot; amp; strDate amp; quot;.xlsquot;
ActiveWorkbook.SaveAs Filename:=strFullName _
, FileFormat:=xlNormal, Password:=quot;quot;, WriteResPassword:=quot;quot;, _
ReadOnlyRecommended:=False, CreateBackup:=False
End SubHope this is what you needed!--
taylorm
------------------------------------------------------------------------
taylorm's Profile: www.excelforum.com/member.php...oamp;userid=28892
View this thread: www.excelforum.com/showthread...hreadid=505054

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()