Word 97—A Release for Developers

Programmability

Word 97 will host Visual Basic for Applications (VBA) for the first time. VBA replaces WordBasic. For most WordBasic developers this will be a welcome change. WordBasic had numerous limitations and. WordBasic developers had to be imaginative to find solutions to resolve these limitations. The VBA family is extensive. Now Word developers can leverage the work of developers from the Visual Basic, Excel, Access and Project communities.

Word is now an automation controller. Word developers can drive applications like Access, Excel, and Project via automation. Word now use Visual Basic inprocess DLL's.

Consistent Across Office

Word joins the Office suite by making many of the objects shared across the Office suite programmatically behave the same. Developers can leverage much of their knowledge in one particular product to another. Developers still must understand the architecture of the host application to be successful.

VBA

The VBA that is in Word 97 is the same as the other Office applications.

Migration

Overall Microsoft has done an outstanding job converting WordBasic macros to VBA code. However there are a number of issues. Most all of these issues are a result of fundamental differences between WordBasic and VBA. The majority of these issues can be resolved with minor edits to the converted macro. As a rule of thumb: all recorded macros will convert without issue, 95% of the simple macros (between 1 to 30 development hours) will convert, 50% of the solutions (40 to 100+ development hours) will convert with out issue.

In the next few weeks Baarns Consulting Group, Inc. will provide a comprehensive conversion article and a Word macro to that will resolve two of the conversion issues.

Object Model

Word 97 provides a comprehensive object model. The designers of the Word object model struggled to provide both a complete and easy-to-use hierarchy of objects. The new object model first daunts most WordBasic developers. In the transition phase WordBasic developers should expect to get disoriented in the object model. After becoming familiar with Word's object model, most WordBasic developers will never want to develop in WordBasic again.

To the Word developer the Range object is the most frequently used Word object. The Range object is used to access or edit data within Word. The Range object is conceptually similar to the Bookmark. It represents a continuous stream of data within the document. Methods and properties off of the Range object are used to manipulate the contents the range represents. One key feature of the Range is that text can be manipulated without moving the insertion point (cursor). Word VBA can also manipulate multiple documents without having to activate any document.

Word 97 has truly simplified access to elements in the document. The following list of objects and collections can be used to access a specific element in the document.

  1. Content
  2. StoryRanges
  3. Sections
  4. Paragraphs
  5. Sentences
  6. Words
  7. Characters
  8. Bookmarks
  9. Fields
  10. Tables
  11. Rows
  12. Columns
  13. Cells
  14. Shapes

Parsing text like a natural language is extremely easy and powerful. For example the following code snippet displays the average number of word per sentence in a document. This was simply done by traversing all of the sentences in the document.

For Each oSentence in ActiveDocument.Sentences
    iCount = iCount + oSentence.Words.Count
Next
MsgBox "Avg. Word/Sentence =" & _
iCount/ActiveDocument.Sentences.Count

'Or the more efficient method.

MsgBox "Avg. Word/Sentence = " & _
ActiveDocument.Words.Count / ActiveDocument.Sentences.Count

Performance

The VBA 5.0 that ships with Office 97 is the same VBA engine of Visual Basic 5.0 Professional. Visual Basic and WordBasic are both interpreted languages, however Visual Basic compiles source code into excodes. This dramatically improves performance at execution time. Some of Visual Basic's intrinsic functions are more than 100 times faster than WordBasic.

WordBasic macros that are converted are not going to be as fast as macros written using VBA and Word objects. This is because all converted WordBasic macros make calls through a WordBasic object. The WordBasic object is designed to be compatible with the WordBasic of Word 6 and 7. However there is a performance hit for using the WordBasic object. Internally Word does look-up to find the appropriate command to execute, whereas macros that use the Word object model make calls directly to the requested function.


  Random Thoughts...
All wiyht. Rho sritched mg kegtops awound?


Copyright© 1996-1999, Baarns Consulting Group, Inc. - All rights reserved.