18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Working with Excel Events 43<br />

.EntireColumn.Interior.ColorIndex = 35<br />

End With<br />

End Sub<br />

This procedure shades the row and column of an active cell, making it easy to identify. The first statement<br />

removes the background color of all cells. Next, the entire row and column of the active cell is shaded light<br />

yellow. Figure 43.2 shows the shading.<br />

ON the CD-ROM<br />

A workbook with this example is available on the CD-ROM. The file is named selection<br />

change event.xlsm.<br />

FIGURE 43.2<br />

Moving the cell cursor causes the active cell’s row and column to become shaded.<br />

CAUTION<br />

You won’t want to use this procedure if your worksheet contains background shading because<br />

the macro will erase it.<br />

Using the BeforeRightClick event<br />

Normally, when the user right-clicks in a worksheet, a shortcut menu appears. If, for some reason, you want<br />

to prevent the shortcut menu from appearing, you can trap the RightClick event. The following procedure<br />

sets the Cancel argument to True, which cancels the RightClick event and, thus, the shortcut<br />

menu. Instead, a message box appears.<br />

Private Sub Worksheet_BeforeRightClick _<br />

(ByVal Target As Excel.Range, Cancel As Boolean)<br />

Cancel = True<br />

MsgBox “The shortcut menu is not available.”<br />

End Sub<br />

753

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!