Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Userform in BeforeSave

I am using Excel 2000, sp2 and I have created a userform that is called in
the Before Save event to provide the reminders to the user. When the
spreadsheet is saved, however, the userform box is appearing twice. Help!


Private Sub CommandButton1_Click()
Unload Reminders
End Sub

Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim UserFileName As Variant
Cancel = True
SaveAsUI = True
Worksheets("Accrual Form").Activate
If Range("m9").Value 0 Then
MsgBox "Invalid account coding entered. Please correct before
saving."
ElseIf Range("n9").Value 0 Then
MsgBox "Monetary amount missing. Please correct before saving."
ElseIf Range("o9").Value 0 Then
MsgBox "Incorrect monetary amount entered. Please correct
before saving."
ElseIf Range("p9").Value 0 Then
MsgBox "Zero monetary amount entered. Please correct before
saving."
ElseIf Range("q9").Value 0 Then
MsgBox "Stat amount missing. Please correct before saving."
ElseIf Range("r9").Value 0 Then
MsgBox "Incorrect stat amount entered. Please correct before
saving."
ElseIf Range("s9").Value 0 Then
MsgBox "Zero stat amount entered. Please correct before saving."
ElseIf Range("t9").Value 0 Then
MsgBox "Stat amount entered for monetary account. Please
correct before saving."
ElseIf Range("w9").Value 0 Then
MsgBox "Negative monetary amount entered with positive stat
amount (or vice versa). Please correct before saving."
ElseIf Range("x9").Value 0 Then
MsgBox "Business unit number missing or invalid. Please correct
before saving."
ElseIf Range("y9").Value 0 Then
MsgBox "Monetary amount entered with no account coding. Please
correct before saving."
ElseIf Range("z9").Value 0 Then
MsgBox "No accrual information entered. Please correct before
saving."
ElseIf Range("aa9").Value 0 Then
MsgBox "Amount entered with more than two decimal places.
Please correct before saving."
ElseIf Range("ab9").Value 0 Then
MsgBox "'$ Amount' equal to 'Stat Amount'. Stat amounts should
reflect number of hours worked, rather than dollar amount paid. Please
correct before saving."
ElseIf Date - Range("d4").Value 7 Then
MsgBox "Incorrect template for accrual month. Please contact
your RVP or RFM for additional instructions."
Else '(IF TEMPLATE PASSES ALL VALIDITY CHECKS)
If Not (Application.WorksheetFunction.IsNA(Range("e5").Va lue))
Then '(AND IF DATA ENTERED)
If ThisWorkbook.Name < Right(Range("e5").Value, 25) Then
'(IF FILE IS NOT THE REQUIRED FILE)
If ThisWorkbook.Name =
"SAVA_Facility_AP_Accrual_Template.xls" Then '(IF FILE HAS NOT BEEN SAVED)
UserFileName =
Application.GetSaveAsFilename(Range("e5").Value) '(PROMPT FOR FILENAME)
Application.ScreenUpdating = False
If UserFileName < False Then
ActiveWorkbook.SaveCopyAs (UserFileName) '(SAVE
AS USER'S FILENAME)
If UserFileName < Range("e5").Value Then
ActiveWorkbook.SaveCopyAs
Filename:=Range("e5").Value '(SAVE AS REQUIRED FILENAME, IF USER DID NOT)
End If
Workbooks.Open Filename:=UserFileName '(OPEN
USER'S FILE)
ThisWorkbook.Close savechanges:=False ' (CLOSE
TEMPLATE FILE)
Else
Application.ScreenUpdating = True
MsgBox "Please enter a filename to save the
file." '(IF USER CANCELS GETSAVEASFILENAME)
Exit Sub
End If
Else '(IF USER'S FILE)
Application.ScreenUpdating = False
ActiveWorkbook.Save '(UPDATE USER'S FILE)
ActiveWorkbook.SaveCopyAs (Range("E5").Value)
'(UPDATE REQUIRED FILE)
Cancel = False
End If
Else '(IF REQUIRED FILE)
Application.ScreenUpdating = False
ActiveWorkbook.Save '(UPDATE REQUIRED FILE)
Cancel = False
End If
Load Reminders
Reminders.Show
Else
Cancel = False '(IF TEMPLATE PASSES VALIDITY CHECKS AND IS
BLANK, SAVE TEMPLATE FORM)
End If
End If
Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Userform in BeforeSave

Emily,
Whilst you use cancel=true so the save dialog is NOT shown for the current
cycle of the code, you call .Save/.SaveAs which fires the event again.
You can avoid this by setting .EnableEvent=false before you call these
methods, then set back to true after.

NickHK

"Emily Edgington" <Emily wrote in
message ...
I am using Excel 2000, sp2 and I have created a userform that is called in
the Before Save event to provide the reminders to the user. When the
spreadsheet is saved, however, the userform box is appearing twice. Help!


Private Sub CommandButton1_Click()
Unload Reminders
End Sub

Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As

Boolean)
Dim UserFileName As Variant
Cancel = True
SaveAsUI = True
Worksheets("Accrual Form").Activate
If Range("m9").Value 0 Then
MsgBox "Invalid account coding entered. Please correct before
saving."
ElseIf Range("n9").Value 0 Then
MsgBox "Monetary amount missing. Please correct before

saving."
ElseIf Range("o9").Value 0 Then
MsgBox "Incorrect monetary amount entered. Please correct
before saving."
ElseIf Range("p9").Value 0 Then
MsgBox "Zero monetary amount entered. Please correct before
saving."
ElseIf Range("q9").Value 0 Then
MsgBox "Stat amount missing. Please correct before saving."
ElseIf Range("r9").Value 0 Then
MsgBox "Incorrect stat amount entered. Please correct before
saving."
ElseIf Range("s9").Value 0 Then
MsgBox "Zero stat amount entered. Please correct before

saving."
ElseIf Range("t9").Value 0 Then
MsgBox "Stat amount entered for monetary account. Please
correct before saving."
ElseIf Range("w9").Value 0 Then
MsgBox "Negative monetary amount entered with positive stat
amount (or vice versa). Please correct before saving."
ElseIf Range("x9").Value 0 Then
MsgBox "Business unit number missing or invalid. Please

correct
before saving."
ElseIf Range("y9").Value 0 Then
MsgBox "Monetary amount entered with no account coding.

Please
correct before saving."
ElseIf Range("z9").Value 0 Then
MsgBox "No accrual information entered. Please correct before
saving."
ElseIf Range("aa9").Value 0 Then
MsgBox "Amount entered with more than two decimal places.
Please correct before saving."
ElseIf Range("ab9").Value 0 Then
MsgBox "'$ Amount' equal to 'Stat Amount'. Stat amounts

should
reflect number of hours worked, rather than dollar amount paid. Please
correct before saving."
ElseIf Date - Range("d4").Value 7 Then
MsgBox "Incorrect template for accrual month. Please contact
your RVP or RFM for additional instructions."
Else '(IF TEMPLATE PASSES ALL VALIDITY CHECKS)
If Not (Application.WorksheetFunction.IsNA(Range("e5").Va lue))
Then '(AND IF DATA ENTERED)
If ThisWorkbook.Name < Right(Range("e5").Value, 25) Then
'(IF FILE IS NOT THE REQUIRED FILE)
If ThisWorkbook.Name =
"SAVA_Facility_AP_Accrual_Template.xls" Then '(IF FILE HAS NOT BEEN SAVED)
UserFileName =
Application.GetSaveAsFilename(Range("e5").Value) '(PROMPT FOR FILENAME)
Application.ScreenUpdating = False
If UserFileName < False Then
ActiveWorkbook.SaveCopyAs (UserFileName)

'(SAVE
AS USER'S FILENAME)
If UserFileName < Range("e5").Value Then
ActiveWorkbook.SaveCopyAs
Filename:=Range("e5").Value '(SAVE AS REQUIRED FILENAME, IF USER DID NOT)
End If
Workbooks.Open Filename:=UserFileName '(OPEN
USER'S FILE)
ThisWorkbook.Close savechanges:=False ' (CLOSE
TEMPLATE FILE)
Else
Application.ScreenUpdating = True
MsgBox "Please enter a filename to save the
file." '(IF USER CANCELS GETSAVEASFILENAME)
Exit Sub
End If
Else '(IF USER'S FILE)
Application.ScreenUpdating = False
ActiveWorkbook.Save '(UPDATE USER'S FILE)
ActiveWorkbook.SaveCopyAs (Range("E5").Value)
'(UPDATE REQUIRED FILE)
Cancel = False
End If
Else '(IF REQUIRED FILE)
Application.ScreenUpdating = False
ActiveWorkbook.Save '(UPDATE REQUIRED FILE)
Cancel = False
End If
Load Reminders
Reminders.Show
Else
Cancel = False '(IF TEMPLATE PASSES VALIDITY CHECKS AND IS
BLANK, SAVE TEMPLATE FORM)
End If
End If
Application.ScreenUpdating = True
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Userform in BeforeSave

Thanks Nick - works great!

"NickHK" wrote:

Emily,
Whilst you use cancel=true so the save dialog is NOT shown for the current
cycle of the code, you call .Save/.SaveAs which fires the event again.
You can avoid this by setting .EnableEvent=false before you call these
methods, then set back to true after.

NickHK

"Emily Edgington" <Emily wrote in
message ...
I am using Excel 2000, sp2 and I have created a userform that is called in
the Before Save event to provide the reminders to the user. When the
spreadsheet is saved, however, the userform box is appearing twice. Help!


Private Sub CommandButton1_Click()
Unload Reminders
End Sub

Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As

Boolean)
Dim UserFileName As Variant
Cancel = True
SaveAsUI = True
Worksheets("Accrual Form").Activate
If Range("m9").Value 0 Then
MsgBox "Invalid account coding entered. Please correct before
saving."
ElseIf Range("n9").Value 0 Then
MsgBox "Monetary amount missing. Please correct before

saving."
ElseIf Range("o9").Value 0 Then
MsgBox "Incorrect monetary amount entered. Please correct
before saving."
ElseIf Range("p9").Value 0 Then
MsgBox "Zero monetary amount entered. Please correct before
saving."
ElseIf Range("q9").Value 0 Then
MsgBox "Stat amount missing. Please correct before saving."
ElseIf Range("r9").Value 0 Then
MsgBox "Incorrect stat amount entered. Please correct before
saving."
ElseIf Range("s9").Value 0 Then
MsgBox "Zero stat amount entered. Please correct before

saving."
ElseIf Range("t9").Value 0 Then
MsgBox "Stat amount entered for monetary account. Please
correct before saving."
ElseIf Range("w9").Value 0 Then
MsgBox "Negative monetary amount entered with positive stat
amount (or vice versa). Please correct before saving."
ElseIf Range("x9").Value 0 Then
MsgBox "Business unit number missing or invalid. Please

correct
before saving."
ElseIf Range("y9").Value 0 Then
MsgBox "Monetary amount entered with no account coding.

Please
correct before saving."
ElseIf Range("z9").Value 0 Then
MsgBox "No accrual information entered. Please correct before
saving."
ElseIf Range("aa9").Value 0 Then
MsgBox "Amount entered with more than two decimal places.
Please correct before saving."
ElseIf Range("ab9").Value 0 Then
MsgBox "'$ Amount' equal to 'Stat Amount'. Stat amounts

should
reflect number of hours worked, rather than dollar amount paid. Please
correct before saving."
ElseIf Date - Range("d4").Value 7 Then
MsgBox "Incorrect template for accrual month. Please contact
your RVP or RFM for additional instructions."
Else '(IF TEMPLATE PASSES ALL VALIDITY CHECKS)
If Not (Application.WorksheetFunction.IsNA(Range("e5").Va lue))
Then '(AND IF DATA ENTERED)
If ThisWorkbook.Name < Right(Range("e5").Value, 25) Then
'(IF FILE IS NOT THE REQUIRED FILE)
If ThisWorkbook.Name =
"SAVA_Facility_AP_Accrual_Template.xls" Then '(IF FILE HAS NOT BEEN SAVED)
UserFileName =
Application.GetSaveAsFilename(Range("e5").Value) '(PROMPT FOR FILENAME)
Application.ScreenUpdating = False
If UserFileName < False Then
ActiveWorkbook.SaveCopyAs (UserFileName)

'(SAVE
AS USER'S FILENAME)
If UserFileName < Range("e5").Value Then
ActiveWorkbook.SaveCopyAs
Filename:=Range("e5").Value '(SAVE AS REQUIRED FILENAME, IF USER DID NOT)
End If
Workbooks.Open Filename:=UserFileName '(OPEN
USER'S FILE)
ThisWorkbook.Close savechanges:=False ' (CLOSE
TEMPLATE FILE)
Else
Application.ScreenUpdating = True
MsgBox "Please enter a filename to save the
file." '(IF USER CANCELS GETSAVEASFILENAME)
Exit Sub
End If
Else '(IF USER'S FILE)
Application.ScreenUpdating = False
ActiveWorkbook.Save '(UPDATE USER'S FILE)
ActiveWorkbook.SaveCopyAs (Range("E5").Value)
'(UPDATE REQUIRED FILE)
Cancel = False
End If
Else '(IF REQUIRED FILE)
Application.ScreenUpdating = False
ActiveWorkbook.Save '(UPDATE REQUIRED FILE)
Cancel = False
End If
Load Reminders
Reminders.Show
Else
Cancel = False '(IF TEMPLATE PASSES VALIDITY CHECKS AND IS
BLANK, SAVE TEMPLATE FORM)
End If
End If
Application.ScreenUpdating = True
End Sub




Reply
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
BeforeSave and Close help Alex Excel Programming 9 February 7th 06 07:36 PM
BeforeSave Steven Excel Programming 2 January 21st 06 05:37 PM
BeforeSave event j23 Excel Programming 0 April 6th 04 11:15 AM
BeforeSave Sub Phil Hageman[_3_] Excel Programming 6 January 14th 04 10:12 AM
VBA - BeforeSave - NEED HELP HRobertson Excel Programming 2 October 23rd 03 06:50 PM


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

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

About Us

"It's about Microsoft Excel"