?
Solved

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

Posted on 2009-04-10
2
Medium Priority
?
992 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

765 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