ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Runtime error when closing the sheetHi all, (https://www.excelbanter.com/excel-programming/359403-runtime-error-when-closing-sheethi-all.html)

praveen_khm[_39_]

Runtime error when closing the sheetHi all,
 

Hi all,
This is a simple macro to hide the sheets if macro is disabled. But I
get an error when I close the worksheet. Can anyone please help me with
this. Other than that, everything seems fine. The problem is only when
closing the worksheet if get an error as " run-time error '1004':
Method ;visible' of object' _worksheet' failed". The code is given
below.


Public bIsClosing As Boolean
Dim wsSheet As Worksheet

Sub HideAll()

Application.ScreenUpdating = False
For Each wsSheet In ThisWorkbook.Worksheets
If wsSheet.CodeName = "TABLE" Then
wsSheet.Visible = xlSheetVisible
Else
wsSheet.Visible = xlSheetVeryHidden
End If
Next wsSheet
Application.ScreenUpdating = True

End Sub

Sub ShowAll()
bIsClosing = False

For Each wsSheet In ThisWorkbook.Worksheets
If wsSheet.CodeName < "TABLE" Then
wsSheet.Visible = xlSheetVisible
End If
Next wsSheet
End Sub


Please help.....


--
praveen_khm
------------------------------------------------------------------------
praveen_khm's Profile: http://www.excelforum.com/member.php...o&userid=30364
View this thread: http://www.excelforum.com/showthread...hreadid=534571


Ivan Raiminius

Runtime error when closing the sheetHi all,
 
Hi,

at least one worksheet must remain visible.

Regards,
Ivan


praveen_khm[_40_]

Runtime error when closing the sheetHi all,
 

Thanks Ivan,
I ll try with that.......


--
praveen_khm
------------------------------------------------------------------------
praveen_khm's Profile: http://www.excelforum.com/member.php...o&userid=30364
View this thread: http://www.excelforum.com/showthread...hreadid=534571



All times are GMT +1. The time now is 08:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com