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
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