![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 2
|
I'm recording a macro to take some columns from one file and put them in another. I want the new file to include in its filename the current date, so it doesn't overwrite the equivalent file from the previous day.
Is there an expression in VB to put the current date in the filename? Is there another way to do this? |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
I don't know what syntax you're using to save the new workbook, but here is a way to add the date to the current workbook name:
HTH |
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Posts: 2
|
thanks, I'll give it a shot!
|
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Quote:
Shouldn't he use, ThisWorkbook.SaveAs Filename:=ThisWorkbook.Name & " " & Format(Now, "mm_dd_yyyy") because the slash marks will create an error.
__________________
Kind regards, Al Chara |
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Al,
Probably should. Good catch. Grrrr! (I should have tested that first) |
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,541
|
The code go's in "ThisWorkbook." Note: you will need to hardcode your file name with a "-" at the end below!
This code will, each time you open the file, save the file with the date at the end of the file name. You can also change the Sub to run on an Event or change the Sub name and run it manually. Hope this helps. JSW Private Sub Workbook_Open() Dim MyDate Dim MyMonth MyDate = Date MyMonth = Month(MyDate) ThisWorkbook.SaveAs Filename:="YourFileNameHere-" & MonthName(MyMonth) & "-" & Day(Date) & "-" & Year(Date) End Sub |
|
|
|
|
|
#7 |
|
New Member
Join Date: May 2002
Posts: 3
|
Is there a way to do this with a cell value?
instead of the date |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Mar 2002
Location: =ActiveCell.Address
Posts: 478
|
Hi beaj,
Yes you can, i.e. ThisWorkbook.SaveAs Filename:=ThisWorkbook.Name & Range("A1").Value Rgds AJ |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|