2011-02-06 5 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