How to enable/disable a button.

  • Thread starter Thread starter Polly
  • Start date Start date
P

Polly

Hi!

I have a problem in writing macro add in. I have created
a button specially for pivot table. When the selected
cell is in pivot table, this button will be enabled and
vice versa. I donno how to write this kind of macro. Can
somebody give me some hints to do?

Thanks!

Polly
 
Hi Polly,

Dim rng As Range
On Error Resume Next
Set rng = ActiveCell.PivotTable.TableRange2
If rng Is Nothing Then
commandbutton1.Enabled = False
Else
commandbutton1.Enabled = True
End If
On Error GoTo 0
 
Thanks! Roger.
I would like to know where the code should be put. I have
tried many places. Only when I put them in a worksheet,
it works. However, some people may not use my worksheet.
They may open or insert a new one.

Polly
 

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

Back
Top