View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nigel[_2_] Nigel[_2_] is offline
external usenet poster
 
Posts: 735
Default excell error on close with commandbutton

Not sure you can Select a sheet when the application is invisible?

--

Regards,
Nigel




"pswanie" wrote in message
...
i got a userform with a command button. (caption "close") used to work
fine.
but i worked on it just now. not the button code it self and not even in
the
workbook before close.

now when i click the close button i get

-----------------------------------------------
microsoft office excel has encountered a problem and needs to close
---------------------------------------------------------------

i exported the 4 userforms and 6 modules and copy the pages in a new
workbook. renamed and imported the userform and modules. then it stoped
for
a couple times but back now again....

here is some of my code

Private Sub Workbook_Open()
Sheets("Sheet1").Select
Worksheets("sheet1").Range("K4").Value = False
Worksheets("sheet1").Range("K5").Value = False
Worksheets("sheet1").Range("K6").Value = False
Worksheets("sheet1").Range("K7").Value = False
Worksheets("sheet1").Range("K8").Value = False


With Application
.Calculation = xlCalculationAutomatic
.MaxChange = 0.001
End With

Application.Visible = False



UserForm1.Show

UserForm1.TextBox1.Value = ""
UserForm1.CheckBox1.Value = False
UserForm1.CheckBox2.Value = False
UserForm1.CheckBox3.Value = False
UserForm1.CheckBox4.Value = False
UserForm1.CheckBox5.Value = False


End Sub
--------------------------------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)

ActiveWorkbook.Save

Application.Visible = True

End Sub

-------------------------------------------------------------------------------

Private Sub CommandButton4_Click()

Unload UserForm1
Sheets("Sheet1").Select
ActiveWorkbook.Save
Application.Quit
End Sub