LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Before Save

The following is my code. When I cancel the "Save As", the "Save As" window
pops up again. However it does not do it when I cancel the "Save". I am
trying automatically name the file based on a named range but allow the user
to change it as needed or cancel it if they decide it is not ready to save
it. When the 2nd window pops up, it does not suggest the name based on the
named range but the name of the file when it was opened (It is like the
normal SaveAs).

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

Dim FName As Variant
Dim MsgResult As VbMsgBoxResult
Dim InitFileName As String
Dim InitFileNameTo As String


With ActiveWorkbook.Sheets("Daily")

Application.EnableEvents = False
On Error GoTo duplicate

InitFileName = Range("LFile").Value & Range("LProject").Value &
" " & "DIR" & " " & Format(Range("DDateFrom"), "dd-mmm-yy") & ".xls"
FName = Application.GetSaveAsFilename(InitFileName, "Excel File
(*.xls),*.xls")

If FName < False Then
ActiveWorkbook.SaveAs FName
Cancel = True
Exit Sub
End If

End With

Application.EnableEvents = True


Exit Sub

duplicate:

Application.EnableEvents = True
Cancel = True

End Sub
--
Thanks!
 
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
Save As and save current numbers not the actual formulas and links Frank Menard Excel Discussion (Misc queries) 2 November 9th 06 09:18 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 02:49 AM.

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"