Reply
 
Thread Tools Display Modes
  #1   Report Post  
PaulBishop PaulBishop is offline
Junior Member
 
Posts: 0
Default string = Range.Text with FormFields

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?
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Stefan Blom[_3_] Stefan Blom[_3_] is offline
external usenet poster
 
Posts: 6,897
Default string = Range.Text with FormFields

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?




--
PaulBishop


  #3   Report Post  
PaulBishop PaulBishop is offline
Junior Member
 
Posts: 0
Default

Quote:
Originally Posted by PaulBishop View Post
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?
Thank you. That seems to be the answer.

Paul
  #4   Report Post  
PaulBishop PaulBishop is offline
Junior Member
 
Posts: 0
Default

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
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Stefan Blom[_3_] Stefan Blom[_3_] is offline
external usenet poster
 
Posts: 6,897
Default string = Range.Text with FormFields

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




--
PaulBishop




  #6   Report Post  
PaulBishop PaulBishop is offline
Junior Member
 
Posts: 0
Default

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

Paul
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating based on text expressions in formfields - Word 2003 ericm Microsoft Word Help 5 October 10th 07 02:25 AM
Eliminate all spaces in a text string aehan Microsoft Word Help 4 June 12th 07 01:34 PM
How to . . Select all text up to a specfied string Simon 1972 Microsoft Word Help 0 June 24th 06 03:50 PM
How to . . Select all text up to a specfied string Rae Drysdale Microsoft Word Help 2 June 23rd 06 12:29 PM
What is a Directory Text String? Lekerul Microsoft Word Help 2 February 21st 05 03:45 PM


All times are GMT +1. The time now is 04:43 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"