Copying the formatted text between two fields?

R

Robin Tucker

I would like to take the formatted text between two fields and place it into
another document.

So far, writing something like this:

theRangeSource = theFirstField.Result
theRangeSource.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
theRangeSource.End = theSecondField.Result.Start

theRangeDestination.FormattedText = theRangeSource.FormattedText

does *not* work correctly. I get bits of the field codes copied into the
second document.

I would either like all formatted text *between* the two fields, or all
formatted text *including* the two fields placed into my second document
(theRangeDestination).

Note: I cannot use the application "Selection" as this is "unsafe" for the
purposes of running my reporter in the background while people are possibly
working with word in the foreground.

How can I do this?


Thanks



Robin
 
R

Robin Tucker

this works (it includes fields):

theRangeSource = theDocument.Range(theFieldStart.Code.Start - 1,
theFieldEnd.Result.End + 1)

this also works (excluding fields):

theRangeSource = theDocument.Range(theFieldStart.Result.End + 1,
theFieldEnd.Code.Start - 1 )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top