Bookmark View Controls

As you learned in Chapter 6, when you create a bookmark in Word while in the Visual Studio IDE, a wrapper object is created called a view control. The Bookmark view control shows up in IntelliSense as a programmable object. And unlike regular Bookmark objects, Bookmark view controls are not late bound; thus, you do not need to refer to the bookmark using its string name from the Bookmarks collection.

Using late-bound objects can cause problems because typographical errors in the name are not found until run time. The names of the Bookmark view controls will be the same names as the bookmarks they wrap. To make the code more readable, you will append the type name to the names of all the view controls. For example, To becomes ToBookmark. The code also updates the Windows Form field names so that instead of using the Hungarian notation of VBA, you use a more .NET-style naming convention, as shown in Listing 12.5. The sample is not only more resilient to document changes but also easier to read and program.

Listing 12.5. Populating Bookmark view controls on an OK button Click event Public Class MainForm

Private Sub btnOK_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles OkButton.Click

' Insert the fields into the bookmarks. With Globals.ThisDocument

.ToBookmark.Text = ToTextBox.Text .FromBookmark.Text = FromTextBox.Text .CCBookmark.Text = CCTextBox.Text .REBookmark.Text = ReTextBox.Text .SubjectBookmark.Text = SubjectTextBox.Text End With

' Close the form. Me.Close() End Sub End Class

0 0

Post a comment