#1
|
|||
|
|||
Tab issues with Word Mac 365
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 |
#2
|
||||
|
||||
Your second macro starts off with:
Set Rng = Selection.Range Since the document already had: .Protect Type:=wdAllowOnlyFormFields before the macro was run, Selection.Range would have been pointing to a formfield and you should be collapsing the range before proceeding: Code:
With Rng .Collapse wdCollapseEnd
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
If I understand you correctly, the code should be added after "Set Rng = Selection.Range? If I do that I get a runtime error "13" type mismatch pointing to the line of code
Code:
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=Pwd |
#4
|
||||
|
||||
You already have 'With Rng'...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Formatting issues (numbering and other issues) in big document. Possibly corrupted. Can anyone help? | Ida | Word | 9 | 07-26-2018 10:22 AM |
Opening a Word 2010 .docx file with Word 2007 and Issues | bwalshnl | Drawing and Graphics | 1 | 03-02-2017 04:13 AM |
Word 2016 vs Word 2003 (issues I can't figure out) | AdventureCapitliast | Word | 6 | 02-23-2017 06:23 AM |
Combining Multiple Word Documents Heading/Figure Issues Word 2007 | grantgibson45 | Word | 1 | 09-10-2012 11:00 PM |
Issues with synchronization log causing send/receive issues | WinSock64 | Outlook | 0 | 01-11-2011 11:29 AM |