Command Button Control

sonicdemonic
05-30-2008, 07:03 AM
I cant seem to find a way to hide the command button control. Basically, I have a excel workbook that has some buttons and macros in it. I want to buttons hidden unless macros are active but it's difficult to do that if the buttons dont hide.
Also, is there a way to test if macros are enabled? Like on workbook load show.butons. Load would work, if that event exists.

Any help or direction is apperciated.

p.s. I am using Excel 2007. Should this be in the .net forum?

Timbo
05-30-2008, 07:50 AM
p.s. I am using Excel 2007. Should this be in the .net forum?
No it's good here.

I had a look at the properties in the design mode dialog, but you're right, there's no "hidden" property - but then I suppose it would be hard to reverse the task manually otherwise ;)

You can set the property using code:
Sheet1.Shapes("CommandButton1").Visible = msoFalse

sonicdemonic
05-30-2008, 07:58 AM
What if I set the size to Height: 0 Width:0

Then when macros are enabled, adjust the size.

Anyone know a way to execute code when macros are enabled. Whether when the document is opened or macros are enabled manually?

Timbo
05-30-2008, 08:15 AM
Why not just hide all the buttons before you give it to the users?

Look up the 'WorkbookOpen Event' topic in your Excel VB help.

sonicdemonic
05-30-2008, 08:32 AM
OK this is what I am trying to accomplish. This workbook is for my work. I enter information into it and send it to them. All they do is open and print, with out macros enabled.

I want to have the buttons hidden without using script ( since macros on their end are disabled ) so they dont see the buttons. I want the button to display if macros are enabled. Currently the buttons are not set to print, printing is not a problem. I just am trying to keep people from seeing the buttons and thinking that since they can see them they will print.

While your solution would hide the buttons, macros would have to be enabled for that to happen, I am assumin..?

They wont resize to zero, only goes down to .01. So if all else fails, I will just keep the buttons at that very small size to minimize visibility.

BTW, excel seems to refer to all scripting as macro(s). Is that correct?

Timbo
05-30-2008, 08:37 AM
No, once again, you hide your buttons using code *before* you deploy the file. You can also code that event to make the buttons visible again if macros are enabled.

Since your users have macros disabled, they will never see the buttons...

sonicdemonic
05-30-2008, 08:40 AM
Very good, I didnt understand that would hide them before deployment.
Thanks!

sonicdemonic
05-30-2008, 08:50 AM
well, I might have hit a problem here.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheet1.Shapes("cmd1").Visible = msoFalse
End Sub

Private Sub Workbook_Open()
Sheet1.Shapes("cmd1").Visible = msoTrue
End Sub



I am not getting any errors but the button is still visible after I save/close the workbook and reopen it.

sonicdemonic
05-30-2008, 08:58 AM
If this helps, Sheet1.Shapes("cmd1").Visible returns -1

sonicdemonic
05-30-2008, 09:03 AM
I am retarded, nevermind. It is working.

Thanks.

Cas
05-30-2008, 10:30 AM
What was the problem? Were you in design mode?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum