Microsoft Office Tutorials and References
In Depth Information
Worksheet_BeforeRightClick Event
Worksheet_Beforerightclick Event
The Worksheet_BeforeRightClick event occurs when you right-click a worksheet cell. The
optional Cancel argument halts the right-click pop-up menu from appearing. In the following
example, when you right-click a cell in column E, the current date and time are entered into that
cell, and column E’s width is autofitted:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
If Target.Column <> 5 Then Exit Sub
Cancel = True
Target.Value = Format(VBA.Now, “MMM DD, YYYY, hh:mm AM/PM”)
Columns(Target.Column).AutoFit
End Sub
Worksheet_followHyperlink Event
The Worksheet_FollowHyperlink event occurs
when you click any hyperlink on the worksheet.
You learn more about command buttons in later
lessons, but as a sneak preview, Figure 11-5 shows
a command button embedded onto a worksheet.
The button is captioned with a website address
but the caption itself is plain text, not actually a
hyperlink. With the following code, when you click
the command button, you are taken to that caption’s
website.
Private Sub CommandButton1_Click()
CommandButton1.Parent.Parent.FollowHyperlink CommandButton1.Caption
End Sub
figurE 11-5
The Worksheet_FollowHyperlink event is available as a worksheet-level event,
but in reality, it is more of a function of the entire workbook. Notice the first
three items in the statement: CommandButton1.Parent.Parent . The parent of
the CommandButton is the worksheet upon which it resides, and the parent of that
worksheet is the workbook itself.
Worksheet_Activate Event
The Worksheet_Activate event occurs when you go to a particular worksheet, typically by clicking
the worksheet’s tab, although any of the other methods of arriving at a worksheet will trigger the
Worksheet_Activate event. Suppose you have a worksheet with one or more pivot tables on it, and
 
Search JabSto ::




Custom Search