Results 1 to 4 of 4

Thread: Name Checkboxes

  1. #1
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    254
    Thanks
    6
    Thanked 1 Time in 1 Post
    I have been programming Excel and Access for years but got blind sided with a Word project this morning.

    Somebody has already built a 30 page questionnaire in Word but the Checkboxes don't have names or bookmarks. I would like to write a loop that does both.

    I am planning a custom function that will compute the answers later.
    Attached Images Attached Images
    Alan

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='MacroAlan' post='790884' date='26-Aug-2009 18:38']Somebody has already built a 30 page questionnaire in Word but the Checkboxes don't have names or bookmarks. I would like to write a loop that does both.[/quote]
    Word version may be relevant here. If those are the checkboxes inserted using the Forms toolbar (legacy controls), they probably have default names, like "Check1". If they are new Word 2007 controls, hmmm, I don't know.

    Do you have a naming scheme in mind? For example, should all the checkboxes in a paragraph share a common prefix?

  3. #3
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    254
    Thanks
    6
    Thanked 1 Time in 1 Post

    Post

    [quote name='jscher2000' post='790893' date='26-Aug-2009 23:45']Word version may be relevant here. If those are the checkboxes inserted using the Forms toolbar (legacy controls), they probably have default names, like "Check1". If they are new Word 2007 controls, hmmm, I don't know.

    Do you have a naming scheme in mind? For example, should all the checkboxes in a paragraph share a common prefix?[/quote]

    The first row of them have names but the rest do not. I assume that they got the first ones looking right and copy/pasted the rest.

    It was created in Word 2003 and updated.

    Good naming convention sounds like Paragraph1Box1, Paragraph1Box2 etc
    Alan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The following macro should be run while the document is unprotected:

    Code:
    Sub NameCheckBoxes()
      Dim p As Long
      Dim f As Long
      Dim n As Long
      For p = 1 To ActiveDocument.Paragraphs.Count
    	n = 0
    	With ActiveDocument.Paragraphs(p).Range.FormFields
    	  For f = 1 To .Count
    		If .Item(f).Type = wdFieldFormCheckBox Then
    		  n = n + 1
    		  .Item(f).Name = "Paragraph" & p & "CheckBox" & n
    		End If
    	  Next f
    	End With
      Next p
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •