ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referencing command button on worksheet from VBA (https://www.excelbanter.com/excel-programming/427963-referencing-command-button-worksheet-vba.html)

Ken Warthen[_2_]

Referencing command button on worksheet from VBA
 
I have several command buttons on a worksheet in an Excel 2007 workbook. I
have a login form that hides/shows worksheets based on the login name of
either Administrator or User. If the login is User I also want to change the
visible property of some of the command buttons to false. I'm having trouble
figuring out how to reference the command buttons on the worksheet from the
VBA module of the login form. Any help or direction would be greatly
appreciated.

Ken

slarbie

Referencing command button on worksheet from VBA
 

Activesheet.Shapes("CommandButton1").Visible = false

where you replace CommandButton1 with the actual names. works whether they
came from the controls or the forms toolbar


"Ken Warthen" wrote:

I have several command buttons on a worksheet in an Excel 2007 workbook. I
have a login form that hides/shows worksheets based on the login name of
either Administrator or User. If the login is User I also want to change the
visible property of some of the command buttons to false. I'm having trouble
figuring out how to reference the command buttons on the worksheet from the
VBA module of the login form. Any help or direction would be greatly
appreciated.

Ken


slarbie

Referencing command button on worksheet from VBA
 
Might be worth adding - if you're not activating the sheets as you loop
through them, it seems you have to refer to them by name as opposed to using
their indexes.

"slarbie" wrote:


Activesheet.Shapes("CommandButton1").Visible = false

where you replace CommandButton1 with the actual names. works whether they
came from the controls or the forms toolbar


"Ken Warthen" wrote:

I have several command buttons on a worksheet in an Excel 2007 workbook. I
have a login form that hides/shows worksheets based on the login name of
either Administrator or User. If the login is User I also want to change the
visible property of some of the command buttons to false. I'm having trouble
figuring out how to reference the command buttons on the worksheet from the
VBA module of the login form. Any help or direction would be greatly
appreciated.

Ken


Ken Warthen[_2_]

Referencing command button on worksheet from VBA
 
Thanks for the help.

"slarbie" wrote:

Might be worth adding - if you're not activating the sheets as you loop
through them, it seems you have to refer to them by name as opposed to using
their indexes.

"slarbie" wrote:


Activesheet.Shapes("CommandButton1").Visible = false

where you replace CommandButton1 with the actual names. works whether they
came from the controls or the forms toolbar


"Ken Warthen" wrote:

I have several command buttons on a worksheet in an Excel 2007 workbook. I
have a login form that hides/shows worksheets based on the login name of
either Administrator or User. If the login is User I also want to change the
visible property of some of the command buttons to false. I'm having trouble
figuring out how to reference the command buttons on the worksheet from the
VBA module of the login form. Any help or direction would be greatly
appreciated.

Ken



All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com