Microsoft KB Archive/286851

From BetaArchive Wiki
Knowledge Base


Results of Text property of a range in macro vary between normal and print layout view in Word

Article ID: 286851

Article Last Modified on 1/29/2007



APPLIES TO

  • Microsoft Office Word 2003
  • Microsoft Word 2002 Standard Edition



This article was previously published under Q286851


SYMPTOMS

When you run a Visual Basic for Applications macro that uses the Text property of a range, the results of the macro may be different in normal view and print layout view.

CAUSE

This behavior can occur when all the following conditions are true:

  • You are using the Text property of the range.
  • The document was edited while the Track Changes option was turned on.
  • The text selection includes tracked changes of deleted text.


WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

290140 How to run the sample code for the Office XP programs from Knowledge Base articles


To work around this behavior, set the ShowAll property for the range to True before you get the Text property of a range. In both normal view and print layout view, the property contains the same text, including the tracked changes of deleted text.

For example, the following macro runs correctly in both normal view and print layout view, because the ShowAll property is set to True:

Sub A()

   Dim RNG As Range

   Selection.SetRange 0,10
   'Select the first 10 characters.

   Set RNG = Selection.Range.Duplicate
   'Set the range to be a duplicate of the current selection.

   RNG.ShowAll = True
   'Use all the text in the selected range, including tracked changes.

   MsgBox Len(RNG.Text)

End Sub
                

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.


Additional query words: VBE VBA WD2002 WD2003

Keywords: kbbug kbnofix KB286851