Solved

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

Posted on 2009-04-10
2
984 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

713 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