Selected

The Selected event handler enables you to take action when focus is moved to the bookmark. For example, you might want to display a task pane. In this section, you'll add code to the Selected event handler of the document to display the Styles and Formatting task pane whenever focus moves from outside the bookmark to an area inside the bookmark.

1. Create a Word document solution.

2. Add a bookmark to the document, and name it Bookmark1.

3. Add the code in Listing 6.25 to the Selected event handler of a Bookmark control.

Listing 6.25. Displaying the Styles and Formatting task pane when a bookmark is selected

Sub Bookmark1_Selected(ByVal sender As Object, ByVal e As _ Microsoft.Office.Tools.Word.SelectionEventArgs) _ Handles Bookmark1.Selected

Application.TaskPanes(Word.WdTaskPanes _ .wdTaskPaneFormatting).Visible = True

End Sub

4. Press F5 to run the code.

5. When the document opens, move your cursor into text that contains the bookmark.

The Styles and Formatting task pane becomes visible (if it isn't already visible) whenever you move your cursor into the area of the bookmark.

0 0

Post a comment