SAVE AS MACRO
Do you mean to add current date to the filename
DefaultFilename = DefaultFilename & Format(Date,"ddmmyyyy") & ".xls"
OR do you mean to display the file name and current date after save.
ThisWorkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
Msgbox "FileName: " & flToSave & vbcrlf & "Current Date :" & Date
--
If this post helps click Yes
---------------
Jacob Skaria
"Neil Holden" wrote:
Superb!! Thanks. One small change if you could be so kind, how to i get it
to display the file name and the current date?
"Joel" wrote:
You can use a file dialog. Change the defaultfolder name as required
Private Sub CommandButton1_Click()
Dim Response As String
Dim msg As String
Dim Style As String
Dim sFilename As String
Dim ans
Dim flToSave As Variant
Dim flName As String
Dim flFormat As Long
msg = "Are you sure you want to Exit the application and Close Excel?"
Style = vbYesNo + vbInformation + vbDefaultButton2
Response = MsgBox(msg, Style)
If Response = vbYes Then
flFormat = ActiveWorkbook.FileFormat
DefaultFolder = "c:\temp"
If Right(DefaultFolder, 1) < "\" Then
DefaultFolder = DefaultFolder & "\"
End If
DefaultFilename = Range("C4")
If Right(UCase(DefaultFilename), 2) < "XLS" Then
DefaultFilename = DefaultFilename & ".xls"
End If
'Create a FileDialog object as a File Picker dialog box.
Set fd = Nothing
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.InitialFileName = DefaultFolder & DefaultFilename
.Filters.Add "Excel Files", "*.xls", 1
.Title = "Save File As..."
.Show
If .SelectedItems.Count = 0 Then
Exit Sub
End If
flToSave = .SelectedItems.Item(1)
End With
ThisWorkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
End If
End Sub
"Neil Holden" wrote:
Below I have code to save as when a macro is pressed.
Can someone tell me firstly, to automatically enter a file name with
reference to whatever is in C4 and to include the date, also to save in a
default location.
Private Sub CommandButton1_Click()
Dim Response As String
Dim msg As String
Dim Style As String
Dim sFilename As String
Dim ans
Dim flToSave As Variant
Dim flName As String
Dim flFormat As Long
msg = "Are you sure you want to Exit the application and Close Excel?"
Style = vbYesNo + vbInformation + vbDefaultButton2
Response = MsgBox(msg, Style)
If Response = vbYes Then
flFormat = ActiveWorkbook.FileFormat
flToSave = Application.GetSaveAsFilename(flName, filefilter:="Excel
Files (*.xls),*.xls", _
Title:="Save File As...")
If flToSave = False Then
Exit Sub
Else
ThisWorkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
|