Word: Setting Form Field Bookmarks
I have two macros. One does what I need it to. The other doesn't. There is a single line of code difference, and I can't figure out why that line is causing a problem.
I need to build a Word form where I can set the bookmark field of each form field.
Code:
Sub Bad()
Documents.Add.Activate
ActiveDocument.Paragraphs.Add
Selection.Tables.Add Selection.Range, 2, 2
Selection.Tables.Item(1).Cell(1, 1).Range.InsertAfter "Text"
Selection.Tables.Item(1).Cell(1, 2).Select
Selection.FormFields.Add Selection.Range, wdFieldFormTextInput
ActiveDocument.FormFields.Item(1).Name = "fldName"
ActiveDocument.FormFields.Item("fldName").Result = "Result"
ActiveDocument.Protect wdAllowOnlyFormFields, True
ActiveDocument.SaveAs "C:\THG\Bad.doc"
ActiveDocument.Close
End Sub
Sub Good()
Documents.Add.Activate
ActiveDocument.Paragraphs.Add
Selection.Tables.Add Selection.Range, 2, 2
Selection.Tables.Item(1).Cell(1, 2).Select
Selection.FormFields.Add Selection.Range, wdFieldFormTextInput
ActiveDocument.FormFields.Item(1).Name = "fldName"
ActiveDocument.FormFields.Item("fldName").Result = "Result"
ActiveDocument.Protect wdAllowOnlyFormFields, True
ActiveDocument.SaveAs "C:\THG\Good.doc"
ActiveDocument.Close
End Sub
I hope this makes sense.