2011-02-06 47 views

回答

2

如果它是一個簡單的傳統領域:

Public Sub ReplaceMergeFields() 
    On Error GoTo MyErrorHandler 

    Dim sourceDocument As Document 
    Set sourceDocument = ActiveDocument 

    Dim myMergeField As Field 
    Dim i As Long 
    For i = sourceDocument.Fields.Count To 1 Step -1 
     Set myMergeField = sourceDocument.Fields(i) 

     myMergeField.Select 
     If myMergeField.Type = wdFieldMergeField Then 
      Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput 
     End If 

     DoEvents 
    Next 

    Exit Sub 

MyErrorHandler: 
    MsgBox "ReplaceMergeFields" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description 
End Sub