Microsoft Office Tutorials and References
In Depth Information
Workbook_SheetBeforeDoubleClick Event
myColumn = Target.Column
Sh.Cells.Interior.ColorIndex = 0
Sh.Rows(myRow).Interior.Color = vbGreen
Sh.Columns(myColumn).Interior.Color = vbGreen
End Sub
Workbook_sheetBeforedoubleclick Event
The Workbook_SheetBeforeDoubleClick event is triggered when a cell on any worksheet is
about to be double-clicked. The double-click effect (usually getting into Edit mode) can be
canceled with the Cancel parameter.
Suppose you have a workbook wherein column A of every worksheet is reserved for the purpose
of placing checkmarks in cells. You do not want to deal with embedding possibly hundreds of real
checkbox objects, so a checkmark-looking character in a cell would suffice.
You can utilize the Workbook_DoubleClick event that would apply only to column A for any
worksheet. The following procedure toggles the effect of placing a checkmark in column A. If the
cell is empty, a checkmark is entered, and if a checkmark is present when the cell is double-clicked
again, the checkmark is removed. As you can see in the code, the “checkmark” is really a
lowercase letter “a” formatted in Marlett font.
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, _
ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 1 Then Exit Sub
Cancel = True
Target.Font.Name = “Marlett”
Target.HorizontalAlignment = xlCenter
If IsEmpty(Target) = True Then
Target.Value = “a”
Else
Target.Clear
End If
End Sub
Workbook_sheetBeforerightclick Event
The Workbook_SheetBeforeRightClick event is triggered when a cell on any worksheet is about to
be right-clicked. The right-click effect of the pop-up menu can be canceled with the Cancel parameter.
Suppose you want to add a utility to your workbook that would allow you to quickly and easily
insert a row above any cell you right-click. A Message Box could ask if you want to insert a row,
and if you answer yes, a row would be inserted. The following procedure is an example of how that
can be handled:
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, Cancel As Boolean)
If MsgBox(“Do you want to insert a row here?”, _
vbQuestion + vbYesNo, _
“Please confirm...”) = vbYes Then
Cancel = True
ActiveCell.EntireRow.Insert
End If
End Sub
Search JabSto ::




Custom Search