Solved

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

Posted on 2009-04-10
2
989 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
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…

734 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