Copy all parenthetical expressions at the end of the document (incl. Fields)

A

andreas

Dear Experts: Below macro is supposed to copy all parenthetical
expressions at the end of the document. It is running fine with the
exception that ...
.... parenthetical expressions within a table causes it to fall into an
endless loop

A SECOND macro similar to the one below should copy all FIELD
EXPRESSIONS, such as user-defined REF-Fields (enclosed in brackets) at
the end of the document. IF I have Word display all the field codes
(Alt + F9) and then adjust below macro to search for ^d, all the field
codes as plain text are copied to the end of the document (not the
field results). I would like Word to make an exact copy of the
parenthetical field expressions and copy them at the end of the
document. Is this feasable?

Could anybody please tell me how to adjust the code ?
Help is appreciated. Thank you very much in advance.

Regards, Andreas

Sub CopyBracketExpressionsAtEndOfDocument()
'Copy all parenthetical expressions at the end of the document.
Regrettably this code falls into an endless loop when it hits
parenthetical expressions in Tables.
Dim rng As Range
Dim rngEnd As Long
Set rng = ActiveDocument.Range
rngEnd = ActiveDocument.Range.End
With rng.Find
.Text = "\([!\)]@\)"

'or "^d" for Fields (Match Wildcards = False). Regrettably only the
field codes as plain text are copied
' to the end of the document, not the field results. But the latter is
what I would like to occur.

.MatchWildcards = True
Do While .Execute() ', Wrap:=wdFindStop)
rng.MoveStart wdCharacter, 1
rng.MoveEnd wdCharacter, -1
rng.Copy

ActiveDocument.Bookmarks("\EndOfDoc").Range.Paste
ActiveDocument.Bookmarks("\EndOfDoc").Range.InsertAfter
vbCr
rng.Collapse wdCollapseEnd
rng.End = rngEnd
Loop
End With
End Sub
 
R

Russ

See some info below:
Dear Experts: Below macro is supposed to copy all parenthetical
expressions at the end of the document. It is running fine with the
exception that ...
... parenthetical expressions within a table causes it to fall into an

endless loop

A SECOND macro similar to the one below should copy all FIELD
EXPRESSIONS, such as user-defined REF-Fields (enclosed in brackets) at
the end of the document. IF I have Word display all the field codes
(Alt + F9) and then adjust below macro to search for ^d, all the field
codes as plain text are copied to the end of the document (not the
field results). I would like Word to make an exact copy of the
parenthetical field expressions and copy them at the end of the
document. Is this feasable?

Could anybody please tell me how to adjust the code ?
Help is appreciated. Thank you very much in advance.

Regards, Andreas

Sub CopyBracketExpressionsAtEndOfDocument()
'Copy all parenthetical expressions at the end of the document.
Regrettably this code falls into an endless loop when it hits
parenthetical expressions in Tables.
Dim rng As Range
Dim rngEnd As Long
Set rng = ActiveDocument.Range
rngEnd = ActiveDocument.Range.End
With rng.Find
.Text = "\([!\)]@\)"

'or "^d" for Fields (Match Wildcards = False). Regrettably only the
field codes as plain text are copied
' to the end of the document, not the field results.

Look up in Word VBA help:
TextRetrievalMode Object
ShowFieldCodes Property

But the latter is
what I would like to occur.

.MatchWildcards = True
Do While .Execute() ', Wrap:=wdFindStop)
rng.MoveStart wdCharacter, 1
rng.MoveEnd wdCharacter, -1
rng.Copy

ActiveDocument.Bookmarks("\EndOfDoc").Range.Paste
ActiveDocument.Bookmarks("\EndOfDoc").Range.InsertAfter
vbCr
rng.Collapse wdCollapseEnd
rng.MoveStart wdCharacter, 1 'go past the ")"
 
A

andreas

See some info below:




Dear Experts: Below macro is supposed to copy all parenthetical
expressions at the end of the document. It is running fine with the
exception that ...
... parenthetical expressions within a table causes it to fall into an
endless loop
A SECOND macro similar to the one below should copy all FIELD
EXPRESSIONS, such as user-defined REF-Fields (enclosed in brackets) at
the end of the document. IF I have Word display all the field codes
(Alt + F9) and then adjust below macro to search for ^d, all the field
codes as plain text are copied to the end of the document (not the
field results). I would like Word to make an exact copy of the
parenthetical field expressions and copy them at the end of the
document. Is this feasable?
Could anybody please tell me how to adjust the code ?
Help is appreciated. Thank you very much in advance.
Regards, Andreas
Sub CopyBracketExpressionsAtEndOfDocument()
'Copy all parenthetical expressions at the end of the document.
Regrettably this code falls into an endless loop when it hits
parenthetical expressions in Tables.
Dim rng As Range
Dim rngEnd As Long
Set rng = ActiveDocument.Range
rngEnd = ActiveDocument.Range.End
With rng.Find
.Text = "\([!\)]@\)"
'or "^d" for Fields (Match Wildcards = False). Regrettably only the
field codes as plain text are copied
' to the end of the document, not the field results.

Look up in Word VBA help:
TextRetrievalMode Object
ShowFieldCodes Property
But the latter is
what I would like to occur.
.MatchWildcards = True
Do While .Execute() ', Wrap:=wdFindStop)
rng.MoveStart wdCharacter, 1
rng.MoveEnd wdCharacter, -1
rng.Copy
ActiveDocument.Bookmarks("\EndOfDoc").Range.Paste
ActiveDocument.Bookmarks("\EndOfDoc").Range.InsertAfter
vbCr
rng.Collapse wdCollapseEnd

rng.MoveStart wdCharacter, 1 'go past the ")"
rng.End = rngEnd
Loop
End With
End Sub

--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Russ,

thank you for your help. It is working. Fine. Thank you. Regards,
Andreas
 

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