Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-10
2
Medium Priority
?
1,000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

596 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