borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (function tooltips)Next Topic (Need Help for Excel Sheet Password) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Locking Worksheets in Excel using VBA
Poster Message
JDizzle
Level: Trainee

Registered: 28-02-2006
Posts: 1

icon Locking Worksheets in Excel using VBA

Hello,

I have a question concerning locking multiple worksheets in Excel using the built in VB.  

Based on whether a certain cell in Sheet 1 is a "Yes" or "No", I want other worksheets within the same book to become inactive.  Lets say that if the cell in sheet 1 is "No" I want worksheets 2 and 3 to be locked, grayed out and basically inactive.  Any ideas on how I woud do this using excels VBA?  I am more experienced using VB.Net if it matters.  
Many Thanks

28-02-2006 at 02:36 PM
View Profile Send Email to User Show All Posts | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Locking Worksheets in Excel using VBA

You can loop through the Worksheet collection and peform action to each sheet...


Dim wkSht As Worksheet
    
    For Each wkSht In ThisWorkbook.Worksheets
    With wkSht
        If .Range("A1") = "Yes" Then
            .Protect
        Else
            .Unprotect
        End If
    End With
    Next


As for the "grayed out", Excel won't do this to signify enabled=False, you would need to set the Color of all the cells to gray, which would destroy any cell coloring you had in place...which is probably not what you want...

____________________________
Eggheads unite! You have nothing to lose but your yolks.

02-03-2006 at 01:42 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Locking Worksheets in Excel using VBA
Previous Topic (function tooltips)Next Topic (Need Help for Excel Sheet Password) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder