PDA

View Full Version : Solved: hide the button for certain time of the day



rrosa1
05-12-2010, 01:43 PM
hi
can i hide the command button in sheet for 9am to next day 8am so in anther ward command button visible for 8am to 9am every morning .
i try some code from the forum but it not working.
i am new to VB so pl help me to code the same
it 's highly appreciated any help
here i am attaching my test wb.

Private Sub CommandButton4_Click()

'Sub findTime()and hide the botton
Dim dHoursMinutes As Double
Dim c As Range
Dim lRow As Long
Dim Button_Name As String

Button_Name = "CommandButton4"

With ActiveSheet.Buttons(Button_Name)
Set c = Now()
dHoursMinutes = Val(Hour(c)) & "." & Minute(c)

If dHoursMinutes >= 8.3 And dHoursMinutes <= 9.3 Then

.Visible = True
Else
.Visble = False
End If
End With

End Sub

mdmackillop
05-12-2010, 02:42 PM
Give this a try

Option Explicit
'In ThisWorkbook
Private Sub Workbook_Open()
Dim Tim As Long
Tim = Format(Now, "hh")
If Tim = 8 Then
Sheets("Main").CommandButton4.Visible = True
Application.OnTime TimeValue("09:00:00"), "TimeOut"
Else
Sheets("Main").CommandButton4.Visible = False
Application.OnTime TimeValue("08:00:00"), "TimeOn"
Application.OnTime TimeValue("09:00:00"), "TimeOut"
End If
End Sub

'In a standard module
Sub TimeOut()
Sheets("Main").CommandButton4.Visible = False
End Sub
Sub TimeOn()
Sheets("Main").CommandButton4.Visible = True
End Sub

rrosa1
05-12-2010, 03:13 PM
hi mdmackillop
it work great
thanks for help