Sometimes I wonder about the mods... Edit was rejected - told to make new answer... This fixes a logical/typo error above.
TWood's comment is correct that with the solution from integratorIT all formatting is lost. The following macro FieldToText REPLACES all fields in your document with their field codes as raw text WITHOUT touching formatting.
The second macro TextToField is for the opposite way: raw code to fields. It looks for the pattern {*}
and tries to convert that to a field. It will work for the fields' raw texts inserted from the first macro, but it may give unpredicted results if there are those combinations of curly braces and whitespace somewhere else in the text where they do not indicate a (former) field function.
Sub FieldToText()
'Selection.HomeKey Unit:=wdStory ' to start from top of document
ActiveWindow.View.ShowFieldCodes = True
Do
With Selection.Find
.Text = "^d"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found = False Then Exit Do
Selection = "{ " & Mid(Selection, 3, Len(Selection) - 2 - 2) & " }"
Selection.Move wdCharacter, 1
Loop While True
End Sub
Sub TextToField()
Dim code As String
'Selection.HomeKey Unit:=wdStory ' to start from top of document
Do
With Selection.Find
.Text = "\{*\}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found = False Then Exit Do
code = Selection
code = Left(code, Len(code) - 1)
code = Right(code, Len(code) - 1)
code = Trim(code)
Selection.Cut
Selection.InsertAfter (code)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=False
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdWord, Count:=1
Loop While True
End Sub