ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error with code... ".Visible" (https://www.excelbanter.com/excel-programming/294786-error-code-visible.html)

Tim[_35_]

Error with code... ".Visible"
 
When I run the code below I get the following error:
Run-time error '1004'
Method 'Visible' of object '_Worksheet' failed

This only displays when I have the debug set to break on all errors.

This code is supposed to hide 8 worksheets and leave number 9 visible...the error occurs with Sheet_7
For Each wSheet In ThisWorkbook.Worksheets
If wSheet.CodeName = "Sheet_9" Then
wSheet.Visible = xlSheetVisible
Else
wSheet.Visible = xlSheetVeryHidden
End If
Next wSheet
....any ideas on what's up?

Tim

fred

Error with code... ".Visible"
 
Tim,
just a thought, you cannot hide all of the worksheets in a workbook so if
"sheet_9" is hidden before you enter this loop then you maybe trying to hide
all the other sheets before making Sheet_9 visible.
You might want to change the code to:

Sheet_9.Visible = xlSheetVisible
For Each wSheet In ThisWorkbook.Worksheets
If not wSheet.CodeName = "Sheet_9" Then
wSheet.Visible = xlSheetVeryHidden
End If
Next wSheet

Fred


"Tim" wrote in message
news:ZO2ec.118362$JO3.81283@attbi_s04...
When I run the code below I get the following error:
Run-time error '1004'
Method 'Visible' of object '_Worksheet' failed

This only displays when I have the debug set to break on all errors.

This code is supposed to hide 8 worksheets and leave number 9

visible...the error occurs with Sheet_7
For Each wSheet In ThisWorkbook.Worksheets
If wSheet.CodeName = "Sheet_9" Then
wSheet.Visible = xlSheetVisible
Else
wSheet.Visible = xlSheetVeryHidden
End If
Next wSheet
...any ideas on what's up?

Tim




JWolf

Error with code... ".Visible"
 
Try "Sheet9" instead of "Sheet_9"

Tim wrote:
When I run the code below I get the following error:
Run-time error '1004'
Method 'Visible' of object '_Worksheet' failed

This only displays when I have the debug set to break on all errors.

This code is supposed to hide 8 worksheets and leave number 9
visible...the error occurs with Sheet_7
For Each wSheet In ThisWorkbook.Worksheets
If wSheet.CodeName = "Sheet_9" Then
wSheet.Visible = xlSheetVisible
Else
wSheet.Visible = xlSheetVeryHidden
End If
Next wSheet
...any ideas on what's up?

Tim



All times are GMT +1. The time now is 12:03 PM.

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