string = Range.Text with FormFields

P

PaulBishop

I wish to copy a section of a document (designated by a bookmark) to
variable. I have tried:

myString = ActiveDocument.Bookmarks("myBookmark").Range.Text

This works fine except that within the bookmarked section there ar
FormFields and I want myString to include whatever the FormFields ar
displaying (i.e. the value
ActiveDocument.FormFields("myFormfield").Result). All that goes int
myString from the FormField is a little square box. Is there a
alternative to .Range.Text which is WYSIWYG
 
S

Stefan Blom

Try using the FormattedText property instead. For example, the following
test macro copies the formatted text, including fields and other data, from
the range defined by the first paragraph of a document to the third
paragraph of the document:

Sub TestMacro()
Dim r As Range
Set r = ActiveDocument.Paragraphs(1).Range.FormattedText
ActiveDocument.Paragraphs(3).Range.FormattedText = r
End Sub

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"PaulBishop" wrote in message

I wish to copy a section of a document (designated by a bookmark) to a
variable. I have tried:

myString = ActiveDocument.Bookmarks("myBookmark").Range.Text

This works fine except that within the bookmarked section there are
FormFields and I want myString to include whatever the FormFields are
displaying (i.e. the values
ActiveDocument.FormFields("myFormfield").Result). All that goes into
myString from the FormField is a little square box. Is there an
alternative to .Range.Text which is WYSIWYG?
 
P

PaulBishop

PaulBishop;492143 said:
I wish to copy a section of a document (designated by a bookmark) to
variable. I have tried:

myString = ActiveDocument.Bookmarks("myBookmark").Range.Text

This works fine except that within the bookmarked section there ar
FormFields and I want myString to include whatever the FormFields ar
displaying (i.e. the value
ActiveDocument.FormFields("myFormfield").Result). All that goes int
myString from the FormField is a little square box. Is there a
alternative to .Range.Text which is WYSIWYG?

Thank you. That seems to be the answer.

Pau
 
P

PaulBishop

The Formfield options are preserved in the variable of type Range. Wha
I need to do next is concatenate several Range variables and strings
then put the finished assembly onto the clipboard. I have tried usin
the PutInClipboard method 0f a DataObject but am losing the Formfield
somewhere along the way. I may do it by creating a second Document
putting the paragraphs into it as Stefan shows, finally usin
Selection.WholeStory, Selection.Copy to put on the clipboard, as I hav
used this successfully before.

Pau
 
S

Stefan Blom

Instead of copying and pasting, you may find using the InsertFile method
helpful if you want to collect data in Word format from different files.

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"PaulBishop" wrote in message

The Formfield options are preserved in the variable of type Range. What
I need to do next is concatenate several Range variables and strings,
then put the finished assembly onto the clipboard. I have tried using
the PutInClipboard method 0f a DataObject but am losing the Formfields
somewhere along the way. I may do it by creating a second Document,
putting the paragraphs into it as Stefan shows, finally using
Selection.WholeStory, Selection.Copy to put on the clipboard, as I have
used this successfully before.

Paul
 
P

PaulBishop

I will have to copy and paste. I need to allow the user to complete
form in Word, selecting from dropdowns in Form Fields, ticking Chec
Boxes. When completed, it needs to selectively assemble text to be cop
and pasted into another application running in a VT100 termina
emulator. That gives you an idea how old the other application is!

Pau
 

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