Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Section A.21. Chapter 21: Working with Widely Used Objects in Word

A.21. Chapter 21: Working with Widely Used Objects in Word


Use Find and Replace via VBA.

Word's Find and Replace utilities are frequently valuable to the VBA programmer. You'll want to master them and also some subtleties associated with their use.


Master It

Sometimes when replacing, you need to go through a document more than once—using a loop structure. Why would you need to repeatedly search and replace the same document?


Solution

In some situations, the act of replacing actually generates new instances of the target of the replacement activity. Let's say you want only single-space strings in a document. (For example, you want sentences separated by only a single space character, but sometimes a typist accidentally presses two spaces following a period.) You set up a search and replace that looks for double-space character strings and replaces them with single-space characters. You have to take into account that there can also be some multiple-space-character strings. Consider a string of six adjacent space characters. During the first pass, your double-to-single search and replace reduces the six-space string to a three-space string (three instances of double spaces would reduce to three instances of single spaces). The second pass would reduce it to a two-space string, requiring yet a third pass through the loop to reach the desired single space. This same situation can apply to multiple paragraph spacing and tabs.


Work with headers, footers, and page numbers.

All Word documents contain headers and footers, even if they are empty. In addition, you can insert various types of headers and footers.


Master It

Name two types of headers you can use in a Word document.


Solution

Here are the major types of Word headers: the primary header, different first-page headers, different even-page headers, and different sets of headers for each of the sections in the document.


Manage sections, page setup, windows, and views.

Among the various ways you can view a document, you sometimes want to have the document automatically scroll to a particular table, graphic, or other target.


Master It

What method of the Window object can be used to easily accomplish this task?


Solution

The ScrollIntoView method of the Window object moves the view to a target you specify.


Manipulate tables.

When you need to manage tables in Word documents, you can employ VBA to work with the Table object to represent a single table. If there is more than one table, they are referenced by a collection of Table objects.


Master It

Name two important and useful objects within the Tables collection or the Table object.


Solution

Some the of most useful objects within a Table object or a Tables collection are:

  • The Rows collection contains the rows in the table. Each row is represented by a Row object.

  • The Columns collection contains the columns in the table. Each column is represented by a Column object.

  • The Cell object provides access to a specified cell directly from the Table object. You can also reach the cells in the table by going through the row or column in which they reside.

  • The Range object provides access to ranges within the table.

  • The Borders collection contains all the borders for the table.

  • The Shading object contains all the shading for the table.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint