[mso] Re: Excel VBA Add Date to File Name - I give up

  • From: Wilson Baptista Junior <wilson@xxxxxxxxxx>
  • To: mso@xxxxxxxxxxxxx
  • Date: Fri, 06 Aug 2004 20:56:32 -0300

Hi Christine,
don't give up <G>
you might try this: At the top of your code put:

Dim MyDate As String
Dim MyDay As String
Dim MyMonth As String
Dim MyYear As String
         MyYear = Year(Date)
         MyMonth = Month(Date)
         If Month(Date) < 10 Then MyMonth = "0" & Month(Date)
         MyDay = Day(Date)
         If Day(Date) < 10 Then MyDay = "0" & Day(Date)
         MyDate = MyYear & MyMonth & MyDay

and, in the appropriate place,

         stFullName = stPath & "\" & stSName & "_" & MyDate

this will give you a filename like Sheet1_20040806
for today's date.

Wilson


At 20:07 6/8/2004, McDonald, Christine, Ms, DCAA wrote:
>Okay, I give up.  I have some VBA code that saves each worksheet to a file
>using the sheet name.  I would like to change it so the name of the new
>file is the sheet name plus the current date.  I have tried everything I
>can think of to get this to work, with no success.
>Here's the part of the code that saves the workbook using the sheet name:
>
>For Each wks In Worksheets
>     wks.Select
>     wks.Copy
>     stSName = ActiveSheet.Name
>     Application.DisplayAlerts = False
>
>stFullName = stPath & "\" & stSName
>     ActiveWorkbook.SaveAs Filename:=stFullName
>
>Can someone help me get it to add the current date to the file name.


*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in 
the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: