Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2022, 08:58 AM
brent chadwick brent chadwick is offline Tab issues with Word Mac 365 Windows 8 Tab issues with Word Mac 365 Office 2013
Advanced Beginner
Tab issues with Word Mac 365
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 08-08-2022, 12:04 AM
macropod's Avatar
macropod macropod is offline Tab issues with Word Mac 365 Windows 10 Tab issues with Word Mac 365 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 08-08-2022, 05:02 AM
brent chadwick brent chadwick is offline Tab issues with Word Mac 365 Windows 8 Tab issues with Word Mac 365 Office 2013
Advanced Beginner
Tab issues with Word Mac 365
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default

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
What I don't understand is why doesn't 2011 and Windows versions flag these issues? Brent
Reply With Quote
  #4  
Old 08-11-2022, 07:40 PM
macropod's Avatar
macropod macropod is offline Tab issues with Word Mac 365 Windows 10 Tab issues with Word Mac 365 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You already have 'With Rng'...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

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
Tab issues with Word Mac 365 Opening a Word 2010 .docx file with Word 2007 and Issues bwalshnl Drawing and Graphics 1 03-02-2017 04:13 AM
Tab issues with Word Mac 365 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft