Re: how to disable/enable command button (ActiveX) using a macro

P

Per Jessen

Hi

You don't have to select the button to enable/disable it, just use the
object reference as recorded:

If Activesheet.Shapes("CommandButton1").Enabled=true then
Activesheet.Shapes("CommandButton1").Enabled=False
Else
Activesheet.Shapes("CommandButton1").Enabled=True
End If

Hopes this helps.
....
Per
 
M

Matt Richardson

Hi

You don't have to select the  button to enable/disable it, just use the
object reference as recorded:

If Activesheet.Shapes("CommandButton1").Enabled=true then
     Activesheet.Shapes("CommandButton1").Enabled=False
Else
     Activesheet.Shapes("CommandButton1").Enabled=True
End If

Hopes this helps.
...
Per

In fact, that's probably where you got the error from, as if the
CommandButton1 isn't on the active sheet, it will throw an exception..

Matt
http://teachr.blogspot.com
 
K

keiji kounoike

There are some ways to disable commandbutton.
One way is

Sub Disable()
ActiveSheet.OLEObjects("CommandButton1").Enabled = False
End Sub

Keiji

enahs_naneek said:
Thank you for your reply
I have entered the code you provided within my "Disable" macro (shown below)
Sub Disable()
'
' Disable Macro
' Macro recorded 05/02/2010 by enahs naneek
'

'
If ActiveSheet.Shapes("CommandButton1").Enabled = True Then
ActiveSheet.Shapes("CommandButton1").Enabled = False
Else
ActiveSheet.Shapes("CommandButton1").Enabled = True
End If
End Sub

Results in error message "object doesnt support this property or method"

This macro (forming part of a larger macro) will be assigned to a second
command button so that when the full macro process is complete i can either
disable or enable the first command button by editing the code to what is
required (true or false)

e.g. "Add" command button enables or disables "Edit" command button.

Will the code you provided work this way

Much appreciated


______________________________________________________
Per said:
Hi

You don't have to select the button to enable/disable it, just use the
object reference as recorded:

If Activesheet.Shapes("CommandButton1").Enabled=true then
Activesheet.Shapes("CommandButton1").Enabled=False
Else
Activesheet.Shapes("CommandButton1").Enabled=True
End If

Hopes this helps.
...
Per
I have tried to create a macro using recorder to disable/enable command
button (ActiveX) with the following code being created
[quoted text clipped - 13 lines]
Any help much appreciated
 
K

keiji kounoike

You're welcome.

Keiji

enahs_naneek said:
Thank you keiji - it worked perfectly
_______________________________
keiji said:
There are some ways to disable commandbutton.
One way is

Sub Disable()
ActiveSheet.OLEObjects("CommandButton1").Enabled = False
End Sub

Keiji
Thank you for your reply
I have entered the code you provided within my "Disable" macro (shown below)
[quoted text clipped - 46 lines]
[quoted text clipped - 13 lines]
Any help much appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top