Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Anderflash Anderflash is offline
external usenet poster
 
Posts: 26
Default Update automatically text from another

Well, I have a document with common text. I want the following:
- On the first line of the second page I want a text equals to the first
line of the first page. (This would be easy putting a bookmark - 'first' for
example) and put on the second page {first}.
- I want that when I change the first line of the first page, this
automatically updates the first line of the second page, but the paragraph
above doesn't do this (I need to press F9).
- This can be solved transforming the first line of the first page in a text
field from the Forms toolbar and checking 'Calculating on exit'. But if I do
this, I need always to protect the document to update automatically the
second page. I'd like the update in a pure text, not in a textfield.

Is there a solution?
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Update automatically text from another

For both your update requirements, you need to use a VBA macro that is named
in the "Run macro on Exit" field of the text form field properties.

The field in the second page needs to be a "REF" field that references the
name of the text form field you want to duplicate - e.g. ir it is Text1, you
need { REF Text1 } or { Text1 }

If you want, us the macro just posted to update all the fields in the
document

Sub UpdateAllFields()
Dim objRange As Word.Range
For Each objRange In ActiveDocument.StoryRanges
Do
objRange.Fields.Update
Set objRange = objRange.NextStoryRange
Loop Until objRange Is Nothing
Next
End Sub

or just update the ranges you need (you'll have to look at the Word
StoryRanges object for more info. on that). If you're unfamiliar with using
VBA macros, try Graham Mayor's page at

http://www.gmayor.com/installing_macro.htm

Peter Jamieson

"Anderflash" wrote in message
news
Well, I have a document with common text. I want the following:
- On the first line of the second page I want a text equals to the first
line of the first page. (This would be easy putting a bookmark - 'first'
for
example) and put on the second page {first}.
- I want that when I change the first line of the first page, this
automatically updates the first line of the second page, but the paragraph
above doesn't do this (I need to press F9).
- This can be solved transforming the first line of the first page in a
text
field from the Forms toolbar and checking 'Calculating on exit'. But if I
do
this, I need always to protect the document to update automatically the
second page. I'd like the update in a pure text, not in a textfield.

Is there a solution?


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Anderflash Anderflash is offline
external usenet poster
 
Posts: 26
Default Update automatically text from another

Peter, thanks for the information. I almost did the document using your
suggestion.
Let me explain more about the document.
I did another question (about the footer) because I'd like to have a text
and the text on the footer needs to be equals to the first line of the body
text.
I put a text field on the first line of this body text (bookmark = 'first'
for example), and on the footer I did {ref first}. I did the update macro
that select all the text and press F9, and I put on exit field from the text
field properties. But there was an error: the document is protected (for
effect of the field), so I edited the VBA code to unprotect before the
actions, and protect. But the protect function erase the text field content
on the first line, although the ref field updates. I changed the action
"select all and press f9" to "open header/footer, go to footer, select the
ref and press f9, go back to body", but it continues to erase the text field.
It seems that the macro on exit from the text field properties is the right
way, but I'm doing something wrong.

Thanks for the attention and for the answers.

"Peter Jamieson" wrote:

For both your update requirements, you need to use a VBA macro that is named
in the "Run macro on Exit" field of the text form field properties.

The field in the second page needs to be a "REF" field that references the
name of the text form field you want to duplicate - e.g. ir it is Text1, you
need { REF Text1 } or { Text1 }

If you want, us the macro just posted to update all the fields in the
document

Sub UpdateAllFields()
Dim objRange As Word.Range
For Each objRange In ActiveDocument.StoryRanges
Do
objRange.Fields.Update
Set objRange = objRange.NextStoryRange
Loop Until objRange Is Nothing
Next
End Sub

or just update the ranges you need (you'll have to look at the Word
StoryRanges object for more info. on that). If you're unfamiliar with using
VBA macros, try Graham Mayor's page at

http://www.gmayor.com/installing_macro.htm

Peter Jamieson

"Anderflash" wrote in message
news
Well, I have a document with common text. I want the following:
- On the first line of the second page I want a text equals to the first
line of the first page. (This would be easy putting a bookmark - 'first'
for
example) and put on the second page {first}.
- I want that when I change the first line of the first page, this
automatically updates the first line of the second page, but the paragraph
above doesn't do this (I need to press F9).
- This can be solved transforming the first line of the first page in a
text
field from the Forms toolbar and checking 'Calculating on exit'. But if I
do
this, I need always to protect the document to update automatically the
second page. I'd like the update in a pure text, not in a textfield.

Is there a solution?



  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Update automatically text from another

I did the update macro
that select all the text and press F9


Don't do it that way: use the macro I suggested:

Sub UpdateAllFields()
Dim objRange As Word.Range
For Each objRange In ActiveDocument.StoryRanges
Do
objRange.Fields.Update
Set objRange = objRange.NextStoryRange
Loop Until objRange Is Nothing
Next
End Sub

Peter Jamieson

"Anderflash" wrote in message
...
Peter, thanks for the information. I almost did the document using your
suggestion.
Let me explain more about the document.
I did another question (about the footer) because I'd like to have a text
and the text on the footer needs to be equals to the first line of the
body
text.
I put a text field on the first line of this body text (bookmark = 'first'
for example), and on the footer I did {ref first}. I did the update macro
that select all the text and press F9, and I put on exit field from the
text
field properties. But there was an error: the document is protected (for
effect of the field), so I edited the VBA code to unprotect before the
actions, and protect. But the protect function erase the text field
content
on the first line, although the ref field updates. I changed the action
"select all and press f9" to "open header/footer, go to footer, select the
ref and press f9, go back to body", but it continues to erase the text
field.
It seems that the macro on exit from the text field properties is the
right
way, but I'm doing something wrong.

Thanks for the attention and for the answers.

"Peter Jamieson" wrote:

For both your update requirements, you need to use a VBA macro that is
named
in the "Run macro on Exit" field of the text form field properties.

The field in the second page needs to be a "REF" field that references
the
name of the text form field you want to duplicate - e.g. ir it is Text1,
you
need { REF Text1 } or { Text1 }

If you want, us the macro just posted to update all the fields in the
document

Sub UpdateAllFields()
Dim objRange As Word.Range
For Each objRange In ActiveDocument.StoryRanges
Do
objRange.Fields.Update
Set objRange = objRange.NextStoryRange
Loop Until objRange Is Nothing
Next
End Sub

or just update the ranges you need (you'll have to look at the Word
StoryRanges object for more info. on that). If you're unfamiliar with
using
VBA macros, try Graham Mayor's page at

http://www.gmayor.com/installing_macro.htm

Peter Jamieson

"Anderflash" wrote in message
news
Well, I have a document with common text. I want the following:
- On the first line of the second page I want a text equals to the
first
line of the first page. (This would be easy putting a bookmark -
'first'
for
example) and put on the second page {first}.
- I want that when I change the first line of the first page, this
automatically updates the first line of the second page, but the
paragraph
above doesn't do this (I need to press F9).
- This can be solved transforming the first line of the first page in a
text
field from the Forms toolbar and checking 'Calculating on exit'. But if
I
do
this, I need always to protect the document to update automatically the
second page. I'd like the update in a pure text, not in a textfield.

Is there a solution?




  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Anderflash Anderflash is offline
external usenet poster
 
Posts: 26
Default Update automatically text from another

Great, I did, thanks. Two questions:
-Why does only the function "activedocument.fields.update" not work?
-Is there a solution without using the text field (using only pure text on
the body)?


  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Update automatically text from another

-Why does only the function "activedocument.fields.update" not work?

Because although it sounds as if it will update /all/ the fields in the
document (and aI wish it did do that because everythign would be much
simpler), "activedocument.fields" only references the "main" story. (Well,
actually it may reference more stories than that, but that's what I think it
does).

-Is there a solution without using the text field (using only pure text on
the body)?


You could /probably/ do it by bookmarking the text (you could do this for
the header as well) and using the macro to replace the text. Because the
operation destroys the bookmark, you have to replace it. However, I haven't
tested it so don't take my word for it!

Let's suppose you have a bookmark on page 2 called page2bm and a bookmark in
the header called headerbm, then the following would probably do it:

Sub UpdateMyBMs()
UpdateBookmark "page2bm", ActiveDocument.Bookmarks("the name of your text
form field").Range.Text
UpdateBookmark "headerbm", ActiveDocument.Bookmarks("the name of your text
form field").Range.Text
End Sub

Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub

The above macro is adapted from Dave Rado's page at

http://word.mvps.org/faqs/macrosvba/...AtBookmark.htm

Peter Jamieson

"Anderflash" wrote in message
...
Great, I did, thanks. Two questions:
-Why does only the function "activedocument.fields.update" not work?
-Is there a solution without using the text field (using only pure text on
the body)?


  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Anderflash Anderflash is offline
external usenet poster
 
Posts: 26
Default Update automatically text from another

Good, but if I replace the text field to a pure text, I will not have the
event 'on exit'. In other words, I don't have an event 'change' in the
document like worksheet_change from the excel and 'on exit' to the pure text.
In that case, I would need the user manipulation (a button or shortcut key)
to activate the bookmark's updating procedure.
But thanks for the information. I don't know if the Word VBA is too
important for me like Excel/Access VBA, but I liked the learning.

"Peter Jamieson" wrote:

-Why does only the function "activedocument.fields.update" not work?


Because although it sounds as if it will update /all/ the fields in the
document (and aI wish it did do that because everythign would be much
simpler), "activedocument.fields" only references the "main" story. (Well,
actually it may reference more stories than that, but that's what I think it
does).

-Is there a solution without using the text field (using only pure text on
the body)?


You could /probably/ do it by bookmarking the text (you could do this for
the header as well) and using the macro to replace the text. Because the
operation destroys the bookmark, you have to replace it. However, I haven't
tested it so don't take my word for it!

Let's suppose you have a bookmark on page 2 called page2bm and a bookmark in
the header called headerbm, then the following would probably do it:

Sub UpdateMyBMs()
UpdateBookmark "page2bm", ActiveDocument.Bookmarks("the name of your text
form field").Range.Text
UpdateBookmark "headerbm", ActiveDocument.Bookmarks("the name of your text
form field").Range.Text
End Sub

Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub

The above macro is adapted from Dave Rado's page at

http://word.mvps.org/faqs/macrosvba/...AtBookmark.htm

Peter Jamieson

"Anderflash" wrote in message
...
Great, I did, thanks. Two questions:
-Why does only the function "activedocument.fields.update" not work?
-Is there a solution without using the text field (using only pure text on
the body)?



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
automatically update and display date at beginging of text in word Tim Microsoft Word Help 2 December 16th 05 06:50 AM
How do I automatically update paragraph numbers in text (3 levels. [email protected] Microsoft Word Help 1 September 14th 05 07:33 PM
Automatically Update Form Text Feild Calculations Brendan Vassallo Microsoft Word Help 1 May 8th 05 07:51 PM
Automatically Update Form Text Fields Brendan Vassallo Microsoft Word Help 3 May 4th 05 05:35 AM
How to automatically update TC field "marked text" wmcdan9569 Microsoft Word Help 3 April 25th 05 08:22 AM


All times are GMT +1. The time now is 11:40 PM.

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"