IncludeFieldCodes doesn't work

J

JO

I am trying to extract text from various ranges in a Word document.

I want the field codes to display as their codes not the resulting text.

I have:

Range.TextRetrievalMode.IncludeFieldCodes = True
MsgBox Range.Text

I get:

6/19/2007

I tried True and False, same result.

However if I do:

activewindow.view.FieldCodes = True
msgbox range.text

I get:

CREATEDATE \* MERGEFORMAT

This is what I want but I don't want to mess with the GUI. So what am I
doing wrong with the TextRetrievalMode.IncludeFieldCodes?

TIA
JO
 
P

Peter Jamieson

A possibility:

The IncludeFieldCodes value has to be set for the specific range /object/
whose text you want to extract, so doing e.g.

Selection.Range.TextRetrievalMode.IncludeFieldCodes = True
MsgBox Selection.Range.Text

wouldn't do what you hoped.


Peter Jamieson
 
R

Russ

JO,
Inline examples from VBA help below.
I am trying to extract text from various ranges in a Word document.

I want the field codes to display as their codes not the resulting text.
ActiveWindow.View.ShowFieldCodes = True
This example toggles field codes in the active window.
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
I have:

Range.TextRetrievalMode.IncludeFieldCodes = True
MsgBox Range.Text

I get:

6/19/2007

I tried True and False, same result.

However if I do:

activewindow.view.FieldCodes = True
msgbox range.text

I get:

CREATEDATE \* MERGEFORMAT

This is what I want but I don't want to mess with the GUI. So what am I
doing wrong with the TextRetrievalMode.IncludeFieldCodes?
This example excludes field codes and hidden text from the range that refers
to the selected text. The example then displays the text in a message box.
If Selection.Type = wdSelectionNormal Then
Set aRange = Selection.Range
With aRange.TextRetrievalMode
.IncludeHiddenText = False
.IncludeFieldCodes = False
End With
MsgBox aRange.Text
End If
 

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