Save Filename as Current Date

Silady

New Member
Joined
Nov 12, 2015
Messages
4
I've been trying different macros to get excel to save as the file with the current date as the filename to no avail. Currently the code I have in my Workbook is this.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Range("aj23,ab15,ad14").Interior.ColorIndex = 4 Then
Cancel = False
ElseIf Range("aj23,ab15,ad14").Interior.ColorIndex <> 4 Then
Cancel = True
MsgBox "Please check that all orders are complete"

End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

If SaveAsUI = False Then
Cancel = True
MsgBox "The 'Save' function for this workbook has " & Chr(10) & "been disabled. Please use 'Save As'.", vbOKOnly + vbInformation, "Save Disabled"
End If

End Sub

Sub Saveas()

Dim Filename
Sdate = " - " & Format(Date, "dd-mm-yyyy")
Filename = "Daily Orders"
ActiveWorkbook.Saveas Filename:=ActiveWorkbook.Path & "/" & Filename & Sdate & ".xlsx"

End Sub

My issue is that it just doesn't appear to do anything. Whenever I click SaveAs it just tries saving the file as its current name
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Has the activeworkbook been saved previously? If no, then there is no path for it.
 
Upvote 0
Yeah, I've saved it. Closed it and run the workbook again and it still doesn't work


Try this (changes are in red):
Rich (BB code):
Sub Saveas()
Dim Filename
Sdate = " - " & Format(Date, "dd-mm-yyyy")
Filename = "Daily Orders"
ActiveWorkbook.Saveas Filename:=ActiveWorkbook.Path & "\" & Filename & Sdate & ".xlsx", FileFormat:=51
End Sub
 
Upvote 0
Still no luck, I've even tried setting a file path for it.
Just tried getting it to work on a blank sheet with no success too. I'm struggling to see what the issue is.
 
Upvote 0
Still no luck, I've even tried setting a file path for it.
Just tried getting it to work on a blank sheet with no success too. I'm struggling to see what the issue is.
What I posted works for me. Are you on a PC or a Mac?
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,542
Members
449,169
Latest member
mm424

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top