Solved

How do I enable/disable a Forms toolbar control using Excel VBA?

Posted on 2009-04-10
2
980 Views
Last Modified: 2012-05-06
I would like to provide a limited number of users access to a sheet containing buttons, which execute macros.  I am using Protection-->Range Permissions to control who (in the network domain) can execute the buttons to run the macro. I assigned macros to Forms toolbar controls but am not sure what code will allow me to disable the buttons when the Password Protection is turned on.  Help!
Private Sub PwProtectSheet()
Dim strPW As String
strPW = "password"
With Worksheets(1)
    .EnableSelection = xlNoSelection
    .Protect Password:=strPW, Contents:=True
    .xlButtonControl(3).Enable = False
End With
 
End Sub

Open in new window

0
Comment
Question by:BenniBoy
  • 2
2 Comments
 
LVL 13

Accepted Solution

by:
StellanRosengren earned 500 total points
ID: 24121739
Hi BenniBoy,
Here is an example of how you can manage the access to forms controls.
The control belongs to the Shapes collection of the worksheet. One property of the shape object is Visible, which I am using here.
Look at the sample code and sample workbook.

Kind regards,
Stellan
Sub ToggleButton()
    Dim shpBtn As Shape
    
    Set shpBtn = ActiveSheet.Shapes("cmdBtn1")
    
    If shpBtn.Visible = msoTrue Then
        shpBtn.Visible = msoFalse
    Else
        shpBtn.Visible = msoTrue
    End If
    
End Sub

Open in new window

Enable-disable-forms-control.xls
0
 
LVL 13

Expert Comment

by:StellanRosengren
ID: 24124054
Thanks for the grade and the points!
/Stellan
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question