Hey Guys, this is for any Mac 365 users out there that have run into tab issues in form fields. The code below runs perfectly in Mac 2011 and Windows, but in Mac 2016,2019 and 365 deletes the default text in the first form field. I have tried a bunch of work-arounds with little success. Any suggestions welcome-Brent
Code:
Sub RLNaturalization()
' Naturalization Macro
Application.ScreenUpdating = False
Dim Rng As Range, FmFld As FormField
Set Rng = Selection.Range
With ActiveDocument
Rng.Collapse wdCollapseStart
'Dropdown Menu for Record Collection
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormDropDown)
With FmFld
.Name = "NaturalizationDD"
.EntryMacro = ""
.ExitMacro = "RLNaturalizationCC"
.Enabled = True
With .DropDown.ListEntries
.Add Name:="Naturalization Records"
.Add Name:="Declaration of Intent"
.Add Name:="Petition For Naturalization"
End With
End With
With Rng
.End = FmFld.Range.End
.Collapse wdCollapseEnd
End With
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=Pwd
End With
Set FmFld = Nothing: Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Code:
Sub RLNaturalizationCC()
Application.ScreenUpdating = False
Dim Prot As Variant, Rng As Range, FmFld As FormField
Const Pwd As String = ""
With ActiveDocument
Prot = .ProtectionType
If .ProtectionType <> wdNoProtection Then
Prot = .ProtectionType
.Unprotect Password:=Pwd
Set Rng = Selection.Range
Select Case .FormFields("NaturalizationDD").Result
'Case for Declaration of Intent
Case "Declaration of Intent"
If InStr(Rng.Text, "Declaration of Intent") = 0 Then
With Rng
'Formfield for Firstname Lastname
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Firstname Lastname", Format:="Title Case"
With Rng
.End = FmFld.Range.End
.InsertAfter " petition for naturalization file, "
.InsertAfter Chr(210) & "Petitions for Naturalization from the "
.Collapse wdCollapseEnd
End With
'Formfield for Court of Naturalization
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Court of Naturalization", Format:="Title Case"
With Rng
.End = FmFld.Range.End
.InsertAfter ", "
.Collapse wdCollapseEnd
End With
'Formfield for Term of Court
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Term of Court"
With Rng
.End = FmFld.Range.End
.InsertAfter ","
.InsertAfter Chr(211) & " record "
.Collapse wdCollapseEnd
End With
'Formfield for Record Number
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "XXX"
With Rng
.End = FmFld.Range.End
.InsertAfter ", "
.Collapse wdCollapseEnd
End With
'Formfield for Lastname
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Lastname", Format:="Title Case"
With Rng
.End = FmFld.Range.End
.InsertAfter "; declaration of intent, "
.Collapse wdCollapseEnd
End With
'Formfield for Record Date
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Record Date"
With Rng
.End = FmFld.Range.End
.InsertAfter "."
.Collapse wdCollapseEnd
FmFld.ExitMacro = "RLUnlinkFieldsNonItalic"
'Bookmark for End of Citation
.Bookmarks.Add Name:="End"
End With
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Select
End With
End If
'Case for Petition For Naturalization
Case "Petition For Naturalization"
If InStr(Rng.Text, "Petition For Naturalization") = 0 Then
With Rng
'Formfield for Firstname Lastname
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Firstname Lastname", Format:="Title Case"
With Rng
.End = FmFld.Range.End
.InsertAfter " petition for naturalization file, "
.InsertAfter Chr(210) & "Petitions for Naturalization from the "
.Collapse wdCollapseEnd
End With
'Formfield for Court of Naturalization
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Court of Naturalization", Format:="Title Case"
With Rng
.End = FmFld.Range.End
.InsertAfter ", "
.Collapse wdCollapseEnd
End With
'Formfield for Term of Court
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Term of Court"
With Rng
.End = FmFld.Range.End
.InsertAfter ","
.InsertAfter Chr(211) & " record "
.Collapse wdCollapseEnd
End With
'Formfield for Record Number
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "XXX"
With Rng
.End = FmFld.Range.End
.InsertAfter ", "
.Collapse wdCollapseEnd
End With
'Formfield for Firstname Lastname
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Firstname Lastname", Format:="Title Case"
With Rng
.End = FmFld.Range.End
.InsertAfter "; petition for naturalization, "
.Collapse wdCollapseEnd
End With
'Formfield for Record Date
Set FmFld = .FormFields.Add(Range:=Rng, Type:=wdFieldFormTextInput)
FmFld.TextInput.EditType wdRegularText, "Record Date"
With Rng
.End = FmFld.Range.End
.InsertAfter "."
.Collapse wdCollapseEnd
FmFld.ExitMacro = "RLUnlinkFieldsNonItalic"
'Bookmark for End of Citation
.Bookmarks.Add Name:="End"
End With
End With
ActiveDocument.Bookmarks("Text1").Range.Fields(1).Result.Select
End If
Case Else: Rng.Text = Chr(211)
End Select
.Protect Type:=Prot, Password:=Pwd, NoReset:=True
End If
End With
Set FmFld = Nothing: Set Rng = Nothing
Application.ScreenUpdating = True
End Sub