Thread: SAVE AS MACRO
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default SAVE AS MACRO

The dialog box doesn't save it only selects the filename. the SAveas
statement does the savings. I suspect the file is getting saved in a
different format than you are expecting. Open up a window explorer and sort
the files by date to see if anything is being saved.

"Neil Holden" wrote:

Thanks for that Jacob, I am now having another problem.

When the save as dialog appears and I press save, its not saving its like
the save button isnt working.

"Jacob Skaria" wrote:

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