LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Save as


Hello again Mark,

Not sure of which version of xl you are using so I have included code to
create and save as xl 97-2003 plus code that I have commented out for xl2007
macro enabled workbook.

From your earlier post I assumed that N2 contained a date and therefore I
have included code to format that date in an acceptable format for a file
name because slashes cannot be used in filenames.

You might want to think about changing code so the date format is "yyyy-mm-dd"
because then your files will then sort in the correct order.

If the user answers No to the msgbox and the file has been changed since the
last save then the system will return the usual warning message to the user
as to whether they want to save the file befor close. I think this is the
best way to go because if the user wants to opt out without save they can but
if they want to save as the original filename they have that option also.


Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim strPath As String
Dim strFilename As String
Dim userResponse As Variant

'Edit "Sheet1" to match the sheet where N2 is.
'Format date so that it does not have slashes _
because slashes cannot be used in a filenames _
and assign filename to string variable.
strFilename = "Week Comm " & _
Format(Sheets("Sheet1").Range("N2"), _
"dd-mm-yyyy")

userResponse = MsgBox("Do you want to save as " _
& strFilename, _
vbYesNo + vbDefaultButton2 + vbQuestion, _
"File Save")

If userResponse = vbYes Then
'Can use a string to create alternative _
path in lieu of ThisWorkbook.Path
strPath = ThisWorkbook.Path

'Concatenate path and filename and save file _
'Use following code for xl versions 97 - 2003
strFilename = strPath & "\" & strFilename & ".xls"
ThisWorkbook.SaveAs Filename:=strFilename, _
FileFormat:=xlNormal, _
CreateBackup:=False

'Use following code for xl2007 macro enabled.
'strFilename = strPath & "\" & strFilename & ".xlsm"
'ThisWorkbook.SaveAs Filename:= strFilename , _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
CreateBackup:=False
Else
'Else only reuired if alternative code
'required if user answers no
End If

End Sub

--
Regards,

OssieMac

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save, save as, page setup dimmed out in unprotected excel sheet? ccKeithJ Excel Discussion (Misc queries) 3 December 14th 07 07:07 PM
disable save and saveas from menubar and save via command button Steve E Excel Programming 5 September 13th 06 11:51 PM
Disable save, save as, but allow save via command button TimN Excel Programming 10 September 1st 06 07:05 PM
How to diasble save and save as menu but allow a save button hon123456 Excel Programming 1 June 12th 06 09:50 AM
Totally Disabling (^ save ) (Save as) and Save Icon Which code do I use: harpscardiff[_10_] Excel Programming 8 November 10th 05 12:24 PM


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"