View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default command button help

Whether the following will work is dependant on whether I have interpreted
your question correctly.

There are 2 types of Command buttons. Forms control and ActiveX control. The
code requires the ActiveX control. In xl2007 select the button from the
ActiveX group. In earlier versions select from the Control Toolbox toolbar.

Right click on the worksheet tab name and copy the code into the VBA editor.
You will see comments re name of command button and also on how to obtain the
code to open, print and close the workbook. I have included a line to disable
the command button.

If you have problems then post the code you finish up with including any
error messages etc.

Private Sub Worksheet_Change(ByVal Target As Range)

'Edit E2 to the range where you place X
If Target = Range("E2") Then
If UCase(Range("E2")) = "X" Then
'Edit CommandButton1 in following lines _
to the name of your command button
Me.CommandButton1.Visible = True
Me.CommandButton1.Enabled = True
Else
Me.CommandButton1.Visible = False
End If
End If

End Sub

'Edit CommandButton1 to name of your command button.
Private Sub CommandButton1_Click()

'Record a macro to open the required workbook, _
print the required worksheets and close the _
workbook.

'Then edit Macro1 in the following line to _
match your recorded macro name. (It might _
not required changing.)

Call Macro1
Me.CommandButton1.Enabled = False

End Sub


--
Regards,

OssieMac