Flyingmeatball
Board Regular
- Joined
- Aug 15, 2007
- Messages
- 65
I keep getting an out of memory error and I'm not quite sure why. I have an excel spreadsheet open that isn't terribly involved. I've set up some security, so I run a macro on the workbook close that forces the user to save and switch to a security tab. Because it saves automatically, i added a userform that would give them the option to cancel out of closing, in case the accidentally clicked on the little x. To run this userform, i set up two public variables. If they click "Yes" on the userform, my exit script should run successfully. If they click "No" on the userform, it should return cancel to the Workbook_Beforeclose, and nothing should happen. Here is the code of my workbook_beforeclose:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RunEscape = False
CancelEscape = False
ExitDialog.Show
MsgBox ("Cancelescape is " & CancelEscape)
MsgBox ("RunEscape is " & RunEscape)
If CancelEscape = True Then Cancel = True
If RunEscape = True Then
'removes assumptions
If ActiveSheet.Name = "MySheet" Then
Range("D:I").Select
Selection = cb.ClearDataND
Selection.clear
End If
'code below will make your created sheet visible
Sheets("Security").Visible = True
'code below will hide your working sheet
Sheets("mySheet").Visible = xlVeryHidden
cb.SetCBAutoLoad (False)
Me.Save
End If
End Sub
and here are my useform buttons:
Private Sub Yesbutton_Click()
RunEscape = True
ExitDialog.Hide
End Sub
Private Sub Nobutton_Click()
CancelEscape = True
ExitDialog.Hide
End Sub
does anyone know why I could be getting this error?
Thanks!
Private Sub Workbook_BeforeClose(Cancel As Boolean)
RunEscape = False
CancelEscape = False
ExitDialog.Show
MsgBox ("Cancelescape is " & CancelEscape)
MsgBox ("RunEscape is " & RunEscape)
If CancelEscape = True Then Cancel = True
If RunEscape = True Then
'removes assumptions
If ActiveSheet.Name = "MySheet" Then
Range("D:I").Select
Selection = cb.ClearDataND
Selection.clear
End If
'code below will make your created sheet visible
Sheets("Security").Visible = True
'code below will hide your working sheet
Sheets("mySheet").Visible = xlVeryHidden
cb.SetCBAutoLoad (False)
Me.Save
End If
End Sub
and here are my useform buttons:
Private Sub Yesbutton_Click()
RunEscape = True
ExitDialog.Hide
End Sub
Private Sub Nobutton_Click()
CancelEscape = True
ExitDialog.Hide
End Sub
does anyone know why I could be getting this error?
Thanks!