A quick way of changing the formatting of entire paragraphs is to change the style (see Figure 16.8). The program below finds the paragraph with the "NO" style and changes it to "HA":

Sub ChangeStyle() Dim wdApp As Word.Application Dim wdRng As Word.Range Dim count As Integer

Set wdApp = GetObject(, "Word.Application")

With wdApp.ActiveDocument

For count = 1 To .Paragraphs.count

Set wdRng = .Paragraphs(count).Range With wdRng

If .Style = "NO" Then .Style = "HA" .Collapse End If End With Next count End With

Set wdApp = Nothing Set wdRng = Nothing End Sub

Figure 16.8

Use styles to quickly change paragraph formatting.

"Word, Excel, PowerPoint, Outlook, and Access all use the same VBA language; the only differences between them are is their object models (for example,.: Excel has a Workbooks object, Word has Documents). Any one oEthese applications can access another application's object model as long as the second application is installed.

To access Word's object library. Excel must establish a link to it. There are two ways of doing this: early binding or late binding With early binding, the reference to the application object is created when the program ls compiled; with late binding, it is created when the program is ran.

Note: Tikis chapter is an introduction to accessing Word from Excel; we ^nll not be reviewing Word's entir e object model or rlie object models of other applications, Refer to the VBA Object Browser in the appropriate applic atiau to lea 111 about other objecr models.


Bookmarks are members of the Document, Selection, and Range objects. They can help make it easier to navigate around Word. Instead of having to choose words, sentences, or paragraphs, use bookmarks to swiftly manipulate sections of a document.

0 0

Post a comment