How to quickly convert field codes to plain text in Word

Here are the steps to quickly convert field codes to plain text in Microsoft Word using VBA:

  1. Press Alt+F11 to open the Microsoft Visual Basic for Applications window.
  2. Click on “Module” from the “Insert” tab to create a new module, then copy and paste the following VBA code into the Module window.

Click the “Run” button (or press F5) to apply the VBA code.

VBA Code 1: Create a New Word Document to Save the Converted Field Codes

Sub ConvertFieldCodesToText()
Dim MyString As String
For Each aField In ActiveDocument.Fields
MyString = MyString & vbCr & Selection.Fields(1).Code.Text
Next aField
Documents.Add
ActiveDocument.Content.InsertAfter MyString
End Sub

VBA Code 2: Convert Field Codes to Text in the Original Document

Sub ConvertFieldCodesToText()
Dim MyString As String
ActiveWindow.View.ShowFieldCodes = True
For Each aField In ActiveDocument.Fields
MyString = “{ ” & Selection.Fields(1).Code.Text & ” }”
Selection.Text = MyString
Next aField
ActiveWindow.View.ShowFieldCodes = False
End SubNote: The first VBA code creates a new Word document to save the converted field codes, while the second VBA code converts the field codes to text directly in the original document. Make sure to choose the appropriate VBA code based on your needs.

How to quickly convert field codes to plain text in Word

How to quickly convert field codes to plain text in Word

Please remember that with the second VBA code, you cannot convert field codes to text from a selection of the document.

 

Gotkey.net
Logo
Compare items
  • Total (0)
Compare
0
Shopping cart