hi all,
i've created an Excel VBA script that shows UserForm1 when clicking on close (the "X" at the top right) without saving. the form simply prompts the user whether to save the file or not (with few more options).
the problem that occurs is: after clicking the submit button, the appears again and only after the second time i pressed the submit button it disappears.
in short: the form appears twice instead of just once (like i want).
my code:
Private Sub Workbook_Before Close(Cancel As Boolean)
If ThisWorkbook.Sa ved = False Then
If ThisWorkbook.Fi leFormat = xlTemplate Then
UserForm1.Show
End If
End If
End Sub
' The submit code:
Private Sub cmdSubmit_Click ()
If UserForm1.NoSav ePrint = True Then
UserForm1.Hide
ThisWorkbook.Cl ose False
End If
If UserForm1.NoSav ePrint = False Then
UserForm1.Hide
Application.Dis playAlerts = False
Application.Scr eenUpdating = False
ThisWorkbook.Sa ve
ActiveWorkbook. SaveAs Filename:="\\sb s2003\OrdersTnu a\JetBackup\Ord erNo_" & Range("E8"), FileFormat:=xlN ormal, Password:="jet" , WriteResPasswor d:="", ReadOnlyRecomme nded:=False, CreateBackup:=F alse
Application.Dis playAlerts = True
Application.Scr eenUpdating = True
Call ThisWorkbook.Pr int2
ThisWorkbook.Cl ose
End If
End Sub
i tried and tried and could not find out where's the error. everything is great except the fact that the form repeats twice.
will be grateful for any ideas.
thanks
i've created an Excel VBA script that shows UserForm1 when clicking on close (the "X" at the top right) without saving. the form simply prompts the user whether to save the file or not (with few more options).
the problem that occurs is: after clicking the submit button, the appears again and only after the second time i pressed the submit button it disappears.
in short: the form appears twice instead of just once (like i want).
my code:
Private Sub Workbook_Before Close(Cancel As Boolean)
If ThisWorkbook.Sa ved = False Then
If ThisWorkbook.Fi leFormat = xlTemplate Then
UserForm1.Show
End If
End If
End Sub
' The submit code:
Private Sub cmdSubmit_Click ()
If UserForm1.NoSav ePrint = True Then
UserForm1.Hide
ThisWorkbook.Cl ose False
End If
If UserForm1.NoSav ePrint = False Then
UserForm1.Hide
Application.Dis playAlerts = False
Application.Scr eenUpdating = False
ThisWorkbook.Sa ve
ActiveWorkbook. SaveAs Filename:="\\sb s2003\OrdersTnu a\JetBackup\Ord erNo_" & Range("E8"), FileFormat:=xlN ormal, Password:="jet" , WriteResPasswor d:="", ReadOnlyRecomme nded:=False, CreateBackup:=F alse
Application.Dis playAlerts = True
Application.Scr eenUpdating = True
Call ThisWorkbook.Pr int2
ThisWorkbook.Cl ose
End If
End Sub
i tried and tried and could not find out where's the error. everything is great except the fact that the form repeats twice.
will be grateful for any ideas.
thanks
Comment