PC Review


Reply
Thread Tools Rate Thread

command button help

 
 
nyyfan_nc
Guest
Posts: n/a
 
      7th Oct 2009


M & E # QTY NAME FILLED NIS COMMENTS PRINT NIS
26-2911-3-0031 1 HOSE, CASE DRAIN PUMP ER10403



have spreadsheet setup like this.
i am trying to hide or unhide a command button in the print nis cell
by placing an "x" in the NIS cell

also when the command button is unhid i want to click it and open another
workbook print it and then close it
then gray out the command button

please help.

M & E # QTY NAME FILLED NIS COMMENTS PRINT NIS
26-2911-3-0031 1 HOSE, CASE DRAIN PUMP x ER10403 button


thanks


 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      7th Oct 2009
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


 
Reply With Quote
 
nyyfan_nc
Guest
Posts: n/a
 
      8th Oct 2009
Work great thanks

but do have another question
can you use a command button to
close a document and bypass the save or not to save question
and not save?

"OssieMac" <(E-Mail Removed)> wrote in message
news:8FF0AA80-7CA6-4AF2-8B98-(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      9th Oct 2009

Private Sub CommandButton2_Click()
'Closes another open workbook without saving

Workbooks("Test.xls").Close SaveChanges:=False

End Sub

Private Sub CommandButton3_Click()
'Closes the workbook containing the _
macro code without saving

ThisWorkbook.Close SaveChanges:=False

End Sub

--
Regards,

OssieMac


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print command from command button in userform causes double chart Mike Jamesson Microsoft Excel Programming 5 11th Aug 2009 03:42 AM
BUG: print command from command button in userform causes double c Mike Jamesson Microsoft Excel Programming 0 10th Aug 2009 04:19 PM
Deselect Command Button by Selecting another Command Button gmcnaugh Microsoft Excel Programming 3 2nd Sep 2008 05:59 PM
Command Button Pictures Taken from Command Bar Button Icons acx@centrum.cz Microsoft Access Forms 0 2nd Dec 2007 12:23 PM
VB's Command Button vs Form's Command Button Ronald Dodge Microsoft Excel Programming 3 24th May 2006 02:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:47 PM.