View Single Post
 
Old 02-12-2017, 04:19 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,344
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To convert field codes to text, you could use the following macro:
Code:
Sub FldCodeToStr()
Application.ScreenUpdating = False
Dim StrFld As String, StrTxt As String, StrChr As String, bFldShw As Boolean, i As Long
StrTxt = "": bFldShw = ActiveWindow.View.ShowFieldCodes
ActiveWindow.View.ShowFieldCodes = True
StrFld = Selection.Text
For i = 1 To Len(StrFld)
  StrChr = Mid(StrFld, i, 1)
  Select Case StrChr
    Case Chr(19)
      StrChr = "{"
    Case Chr(21)
      StrChr = "}"
    Case Else
  End Select
  StrTxt = StrTxt + StrChr
Next
Selection.TypeText StrTxt
ActiveWindow.View.ShowFieldCodes = bFldShw
Application.ScreenUpdating = True
End Sub
To reverse the process, see Convert Text Representations of Fields to Working Fields in the Mailmerge Tips and Tricks thread in the Mailmerge forum:
https://www.msofficeforums.com/mail-...ps-tricks.html
The code there turns a text representation of a field code into a working field. Not only does it do so for fields represented via parenthetic expressions (i.e. { }) but also for mergefields represented by chevrons (i.e. « »).

Do note that both processes lose any formatting the applied to the content within quoted strings or via the Charformat switch. If the retention of such formatting is required, it is advisable to run it on a copy of any such fields so the formatting can be restored post-conversion.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote