Hi All,
I've been using the following code successfully for years. Today I would get the error 1004:Unable to set the visible property of the worksheet class. All my searches came up with someone not realizing they had protected the workbook. As you can see, the first thing I do before trying to set the worksheet visible is to unprotect the workbook. In frustration and on a lark I tried .Sheets("items").Visible = True and it worked. These kind of intermittent errors in Excel VBA are very frustrating. Can anyone tell me what I am doing wrong?
Thanks.
Sub Unprotect() Dim c As Integer Dim wkbk As Workbook Application.ScreenUpdating = False With Application.FileSearch .LookIn = ThisWorkbook.Path .FileType = msoFileTypeExcelWorkbooks If .Execute > 0 Then For c = 1 To .FoundFiles.Count Set wkbk = Workbooks.Open(.FoundFiles(c)) With wkbk .Unprotect "mypassword" .Sheets("items").Visible = xlVisible .Save .Close End With Next c Else MsgBox "No workbooks" End If End With Application.ScreenUpdating = True End Sub
Hello colinnwn,
I am not sure what your question is. I can tell you that the Excel constant xlVisible is equal to -1. The boolean value True also equals -1. So in this case, it doesn't matter which one use.
Sincerely,
Leith Ross
The property you want is Hidden, not Visible, and its enumerations are xlSheetVisible, xlSheetHidden, and xlSheetVeryHidden.
Edit:
xlVisible = 12, not 1.
xlSheetVisible = 12
Last edited by shg; 01-06-2009 at 07:08 PM.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
my object browser says
xlVisible = 12
xlSheetVisible = -1
Thanks romperstomper, that makes more sense. I knew the visible property worked previously. I don't remember changing the code to xlvisible vs. xlsheetvisible, but the fact xlsheetvisible enumerates to the same thing that ended up working for me (true), is rational.
That was a typo, sorry -- the point I was trying to make was that they were different.Originally Posted by Andy
That was not a typo, it was a brain cramp.Originally Posted by romperstomper
Two errors in one post ...![]()
![]()
![]()
![]()
![]()
Last edited by shg; 01-09-2009 at 02:51 PM.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks