View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Reference Cmd Button

Option Explicit
Private Sub Workbook_Open()

With Me.Worksheets("Sheet1")
.CommandButton1.Visible = True
.CommandButton2.Visible = False
End With

End Sub

(change the names of the buttons to match yours)

I'd use the workbook_Open event. If you use _beforeclose, then the workbook
will have to be saved--and I bet you won't know if the other changes should be
saved.

ps. have you thought of just enabling/disabling them?

With Me.Worksheets("Sheet1")
.CommandButton1.Enabled = True
.CommandButton2.Enabled = False
End With


CR wrote:

I have a worksheet, we'll say Sheet 1, that does a web query. I have two
command buttons, from the control toolbox, set up that turn the query
on/off.

On either the workbook Open or Beforeclose, I want to make one of the
buttons visible = false.

When I put the code in ThisWorkbook module, I don't seem to know how to
reference the button (or maybe the sheet?)

I get an object required error as soon as it gets to my Cmdb_Stop.Visible =
False line.

How do I properly point to it?

Thanks


--

Dave Peterson