I have a workbook with three sheets. I am wondering if is is possible to run an on open event that performs functions on Sheet1?
For example, the following looks through the D column and if the date in that column matches today's date a toggle button is displayed. I want the toggle button to be hidden by default when the workbook is opened and then unhidden if the criterion is matched.
Sub Revisit()
Dim xdate As Date
Dim lastrow As Long
Dim c As Range
Dim Rng As Range
Dim count As Long
count = 0
lastrow = Range("A" & Rows.count).End(xlUp).Row
Set Rng = Range("D2:D" & lastrow)
For Each c In Rng
xdate = c.Value
If Month(Date) = Month(xdate) And Year(Date) = Year(xdate) Then
count = count + 1
Else
End If
Next
If count > 0 Then
ToggleButton1.Visible = True
ToggleButton1.BackColor = RGB(255, 0, 0)
ToggleButton1.Caption = "Re-Visit"
ToggleButton1.Font.Bold = True
ToggleButton1.Font.Size = 18
Else
ToggleButton1.Visible = False
End If
End Sub
How do I go about setting this up to run on workbook open?
Bookmarks