View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
minimaster minimaster is offline
external usenet poster
 
Posts: 73
Default Hide Command button - still use it

You can give one and the same button "hidden" functions by using in
addition the keyboard when clicking it.
for example the hidden sheet is only shown when you press the shift
key while clicking the button (or may be the Ctrl key).

the VBA code for that is relatively simple:

Option Explicit
'-------------------------------
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey
As Long) As Integer
'-------------------------------
Function Key_pressed(key_to_check As Long) As Boolean
If GetAsyncKeyState(key_to_check) And &H8000 Then
Key_pressed = True
Else
Key_pressed = False
End If
End Function
'----------------------------
Sub Button1_Click()
If Key_pressed(vbKeyControl) Then ' alternatively use the
"vbKeyShift" constant for the shift key
' do something special, unhide hidden sheet or show the
worksheets from an add-in
ThisWorkbook.IsAddin = False
ThisWorkbook.Activate
Else
' here comes the standard functionality when clicking Button1
without pressing the Ctrl key at the same time
' ....
End If
End Sub