Word 将我的文档文本移动到了字段代码内。我该如何将其恢复?

Word 将我的文档文本移动到了字段代码内。我该如何将其恢复?

好的。随机问题,不知何故,Word 设法将我的文档的全部内容(7500 多个单词,包括引文管理器的各种字段代码)移动到覆盖整个文档的字段代码中。第一页如下所示。

在此处输入图片描述

如果我将字段转换为文本,它会清除所有内容,因为就 Word 而言,代码实际上不会执行任何操作。我无法可靠地选择字段的内容,因为文档太大。

有没有办法将其恢复为正常文本?最好保留嵌入的字段代码?

谢谢

答案1

当您选择所有内容并按下 Ctrl+F9 而不是 F9 时,可能会发生这种情况。

选项1

您可以在错误字段的开头和结尾处添加一个额外的空格,然后将这两个空格之间的所有内容复制到新文档中。然后删除错误的字段并将内容复制/粘贴回去。

选项 2

你可以通过 Word MVP Graham Mayor 的字段代码到文本转换器并返回。该页面还包含如下所示的宏。(我建议使用插件。)转换回来之前,删除外部字段括号。您可能需要逐个字段进行转换。使用文档的副本执行此操作,因为您必须恢复格式。

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

相关内容