+ Reply to Thread
Results 1 to 7 of 7

Thread: Unable to set the visible property of the worksheet class

  1. #1
    Registered User
    Join Date
    01-06-2009
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    2

    Question Unable to set the visible property of the worksheet class

    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

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979
    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

  3. #3
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777
    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

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351
    my object browser says

    xlVisible = 12
    xlSheetVisible = -1
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274
    Quote Originally Posted by shg View Post
    The property you want is Hidden, not Visible
    The Worksheet class does not have a Hidden property, but does have a Visible one. The problem is just the constant, unless I'm going nuts (again).

  6. #6
    Registered User
    Join Date
    01-06-2009
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    2

    Cool Ah ha...

    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.

  7. #7
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777
    Quote Originally Posted by Andy
    my object browser says

    xlVisible = 12
    xlSheetVisible = -1
    That was a typo, sorry -- the point I was trying to make was that they were different.
    Quote Originally Posted by romperstomper
    The Worksheet class does not have a Hidden property, but does have a Visible one. The problem is just the constant, unless I'm going nuts (again).
    That was not a typo, it was a brain cramp.

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0