Skip to main content

Problem:

If you are using the "InsertAfter" method of the selection object to enter text into a Word document then the selection is expanded with the new text.

This can cause problems when you jsut want to apply formatting (Bold etc) to some of the text. If you apply Bold then it applies to all the selection.

Resolution:

You can use the "Collapse" method of the selection object reset the selection down to just the current text entry position. Some example code to perform this is:-

          *> Here we want to do collapse and bold the next text

           set wdCollapseEnd of ws-direction to true   

           invoke theSelection "Collapse" using ws-direction

           invoke theSelection "InsertAfter" using

          "This is some text that need to be bold" & x"0d"

           invoke theSelection "getFont" returning theFont

           set Size-CBL  to 12

           invoke theFont "setSize" using by value Size-CBL

           set Size-CBL  to 1

           invoke theFont "setBold" using by value Size-CBL

           invoke theFont "setUnderline" using by value Size-CBL

           invoke theFont "finalize"  returning theFont

           invoke theSelection "finalize" returning theSelection

For full details on the "Collapse" method please see the help provided with Microsoft Word.

Old KB# 1273