I am trying to safe a file including todays date. The macro will exacute, but the date is wrong and strung together
i.e. Vendor Validation Report 40644.xls \
I have tried using & Format(NOW, MM - DD - YY) & ".xls", as well as & Format(Date, MM - DD - YY) & ".xls"
niether seem to pull the correct date or format it in "MM-DD-YY" format
Any Tips - I am very new to VBA
thanks
You can View my code below:
Sub SAVE_TEST()
'
' SAVE_TEST Macro
'
'
'
ChDir "C:\~VENDOR_VALIDATION"
ActiveWorkbook.SaveAs Filename:= _
"C:\~VENDOR_VALIDATION\Vendor Validation Report" & Format(Date, MM - DD - YY) & ".xls", FileFormat:=xlExcel8, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
With ActiveSheet
Range("A1").Select
End With
End Sub
hi,
try this
' "C:\~VENDOR_VALIDATION\Vendor Validation Report" & Format$(Date, "dd-mmm-yyyy") '
Regards, John
Nope that doesnt work either. it generate's the same bogus date.....
HI,
You should use the forum format for the code tags.
Here is your code which i added a correction too.
You can however record a macro to see how to format the SaveAs file.
Format(Date, "MM - DD - YY")''' note the " " "Sub SAVE_TEST() ' ' SAVE_TEST Macro ' ' ' ChDir "C:\~VENDOR_VALIDATION" ActiveWorkbook.SaveAs Filename:= _ "C:\~VENDOR_VALIDATION\Vendor Validation Report\" & Format(Now, "MM - DD - YY") & ".xls" With ActiveSheet Range("A1").Select End With End Sub
Last edited by Charles; 04-11-2011 at 04:03 PM. Reason: corrected code to shorter code
Charles
There are other ways to do this, this is but 1 !
Be Sure you thank those who helped.
IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.
These do not work, I have tried so many variations, but none of them work. I am using Excel 2007, could this be part of the issue?
In addition, nobody has included the code for the file extention type. and if I dont script the excel format type (i.e. 97-2003 or 2007) it will save but I loose all the formatting on save and when I open it kicks me a warning that the file is not in the format of its listed extention....
Hi,
It might help if we can see a copy of your workbook. All of the codes that were posted worked.
Charles
There are other ways to do this, this is but 1 !
Be Sure you thank those who helped.
IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.
I have attached the Workbook I am attempting to save with the current date, and I attached the PERSONAL.XLS that houses all the code. Hope this helps
Hi,
The following is the code I used for my test.
This is the result' this is the saved as name Copy of North Vendor Validation Report 04 - 13 - 2011 ChDir "Z:\MacExcel\ExcelFiles" ActiveWorkbook.SaveAs Filename:= _ "Z:\MacExcel\ExcelFiles\Copy of North Vendor Validation Report " & Format(Now, "MM - DD - YYYY") & ".Xls" _ , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False
Copy of North Vendor Validation Report 04 - 13 - 2011
Try the following code in your Personal code Module7
Sub SAVE_TO_C_DRIVE() ' ' SAVE_TO_C_DRIVE Macro ' ' Keyboard Shortcut: Ctrl+e ' Application.DisplayAlerts = False Application.ScreenUpdating = False Application.Run "PERSONAL.XLSB!FINAL_EDIT" Application.Run "PERSONAL.XLSB!REMOVAL_BLANKET_REMOVE_BY_FILTER" Application.Run "PERSONAL.XLSB!STATUS_REMOVE_BY_FILTER" Application.Run "PERSONAL.XLSB!FREEZE" Cells.Select Cells.EntireColumn.AutoFit Range("A1").Select '****************************************** 'WHEN VENDOR SHAEPOINT IS READY ACTIVATE 'ChDir "C:\~VENDOR_VALIDATION" 'ActiveWorkbook.SaveAs Filename:= _ '"Z:\North Vendor Validation Report.xls", FileFormat:=xlExcel8, _ ' Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _ 'CreateBackup:=False '****************************************** ChDir "C:\~VENDOR_VALIDATION" ActiveWorkbook.SaveAs Filename:= _ "C:\~VENDOR_VALIDATION\North Vendor Validation Report " & Format(Now, "MM - DD - yyyy") & ".xls", FileFormat:=xlExcel8, _ Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _ CreateBackup:=False Application.ScreenUpdating = True With ActiveSheet Range("A1").Select End With Application.DisplayAlerts = True End Sub
Charles
There are other ways to do this, this is but 1 !
Be Sure you thank those who helped.
IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.
I completly belive it is working on other machines, but not only have I tried this exact script, I retried it and still it doesnt work, it kicks this invalid dummy date. Is this a problem with my excel system referance?
hi CBG,
it works for me too! just for a test, run with this code and see if it works for you with a test file.
Sub Button2_Click() ActiveSheet.Copy 'Saves filename as value of A1 plus the current date Dim newFile As String, fName As String ' Don't use "/" in date, invalid syntax fName = Range("A1").Value 'Change the date format to whatever you'd like, but make sure it's in quotes newFile = fName & "Sheet1 - " & Format$(Date, "dd-mmm-yyyy") ' Change directory to suit your PC, including USER NAME ChDir _ "C:\users\john\Desktop" ActiveWorkbook.SaveAs Filename:=newFile End Sub
Regards, John
John:
That worked, Why is it that this code worked and none of the other variations did?
Thanks for the help everyone...
Brad
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks