您可以通过 Word MVP Graham Mayor's Field Code to Text 转换器运行它并返回。该页面还具有如下所示的宏。(我建议使用加载项。)在转换回来之前删除外部字段括号。您可能必须逐个字段地进行转换。使用您的文档副本执行此操作,因为您必须恢复格式。
选项 3
您可以将该字段设置为工作字段。在字段的QUOTE "开头加上一个,在结尾加上另一个引号"。
Sub FieldCodeToString()
Dim oRng as Range
Dim Fieldstring As String
Dim NewString As String
Dim CurrChar As String
Dim CurrSetting As Boolean
Dim fcDisplay As Object
Dim MyData As DataObject
Dim X As Long
NewString = ""
Set fcDisplay = ActiveWindow.View
Application.ScreenUpdating = False
CurrSetting = fcDisplay.ShowFieldCodes
If CurrSetting <> True Then fcDisplay.ShowFieldCodes = True
Set oRng = Selection.Range
Fieldstring = oRng.Text
For X = 1 To Len(Fieldstring)
CurrChar = Mid(Fieldstring, X, 1)
Select Case CurrChar
Case Chr(19)
CurrChar = "{"
Case Chr(21)
CurrChar = "}"
Case Else
End Select
NewString = NewString + CurrChar
Next X
oRng.Text = NewString
Set MyData = New DataObject
MyData.SetText NewString
MyData.PutInClipboard
fcDisplay.ShowFieldCodes = CurrSetting
End Sub
并且,要扭转这个过程:
Sub FieldStringToCode()
' Based on a macro provided by Paul Edstein
' Converts "textual" field codes into real field codes
' To do the conversion, simply paste the "textual" field codes
' into your document, select them and run the macro.
Dim RngFld As Range
Dim RngTmp As Range
Dim oFld As Field
Dim StrTmp As String
Dim sUpdate As String
Dim bFldCodes As Boolean
Const Msg1 = "Select the text to convert and try again."
Const Msg2 = "There are no field strings in the selected range."
Const Msg3 = "Unmatched field brace pairs in the selected range."
Const Title1 = "Error!"
Const Title2 = "Update fields?"
Application.ScreenUpdating = False
bFldCodes = ActiveDocument.ActiveWindow.View.ShowFieldCodes
If Selection.Type <> wdSelectionNormal Then
MsgBox Msg1, vbExclamation + vbOKOnly, Title1
Exit Sub
End If
If InStr(1, Selection.Text, "{") = 0 Or InStr(1, Selection.Text, "}") = 0 Then
MsgBox Msg2, vbCritical + vbOKOnly, Title1
End If
If Len(Replace(Selection.Text, "{", vbNullString)) <> Len(Replace(Selection.Text, "}", vbNullString)) Then
MsgBox Msg3, vbCritical + vbOKOnly, Title1
Exit Sub
End If
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
Set RngFld = Selection.Range
With RngFld
.End = .End + 1
Do While InStr(1, .Text, "{") > 0
Set RngTmp = ActiveDocument.Range(Start:=.Start + InStr(.Text, "{") - 1, End:=.Start + InStr(.Text, "}"))
With RngTmp
Do While Len(Replace(.Text, "{", vbNullString)) <> Len(Replace(.Text, "}", vbNullString))
.End = .End + 1
If .Characters.Last.Text <> "}" Then .MoveEndUntil cset:="}", Count:=Len(ActiveDocument.Range(.End, RngFld.End))
Loop
.Characters.First = vbNullString
.Characters.Last = vbNullString
StrTmp = .Text
Set oFld = ActiveDocument.Fields.Add(Range:=RngTmp, Type:=wdFieldEmpty, Text:="", PreserveFormatting:=False)
oFld.Code.Text = StrTmp
End With
Loop
ActiveDocument.ActiveWindow.View.ShowFieldCodes = bFldCodes
.End = .End - 1
If bFldCodes = False Then .Fields.ToggleShowCodes
.Select
End With
Application.ScreenUpdating = True
sUpdate = MsgBox("Do you wish to update the fields?" & vbCr + vbCr & _
"Note that if the converted fields include ASK or FILLIN fields, " & _
"updating will force the prompt for input to those fields", vbYesNo, Title2)
If sUpdate = vbYes Then RngFld.Fields.Update
Set RngTmp = Nothing
Set RngFld = Nothing
Set oFld = Nothing
End Sub
当您选择所有内容并按 Ctrl+F9 而不是 F9 时,可能会发生这种情况。
选项1
您可以在错误字段的开头和结尾放置一个额外的空格,然后将这两个空格之间的所有内容复制到新文档中。然后删除错误字段并将内容复制/粘贴回来。
选项 2
您可以通过 Word MVP Graham Mayor's Field Code to Text 转换器运行它并返回。该页面还具有如下所示的宏。(我建议使用加载项。)在转换回来之前删除外部字段括号。您可能必须逐个字段地进行转换。使用您的文档副本执行此操作,因为您必须恢复格式。
选项 3
您可以将该字段设置为工作字段。在字段的
QUOTE "
开头加上一个,在结尾加上另一个引号"
。并且,要扭转这个过程: