Option Button help

L

LEU

I had someone here at work created a form with a large number of option
buttons. The problem is they created the first one and then copied it and
pasted it all over the form. Now the button names are hard to follow on the
form. The first option button on the form is named OptionButtion1 and the
next one is named OptionButton 923111. My question is there a way to write a
one time macro to rename all the OptionButtons starting at the top of the
document? So the first button would be OptionButton1, the second would be
OptionButton2 and so on.

LEU
 
S

spunkymuffmonkey

Hi Leu,

Having been down this street before I managed to source a macro that
reindexes/renames all formfields within a document starting from the top.

I unfortunately cannot remember whom or where I got this macro from so I
cannot give them the credit, but here is the macro anyways, if you're unsure
how to use this macro then please let me know and I shall issue further
instructions. Hope this helps.

Code is:=============


Sub GlobalRenameFormFields()
Dim oFrmFlds As FormFields
Dim pIndex As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim oVar As Variant
pIndex = 0
i = 0
j = 0
k = 0
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
Set oFrmFlds = ActiveDocument.FormFields
For pIndex = 1 To oFrmFlds.Count
oFrmFlds(pIndex).Select
Select Case oFrmFlds(pIndex).Type
Case wdFieldFormTextInput
oVar = oFrmFlds(pIndex).Result
i = i + 1
With Dialogs(wdDialogFormFieldOptions)
.Name = "Text" & i
.Execute
End With
oFrmFlds(pIndex).Result = oVar
Case wdFieldFormCheckBox
oVar = oFrmFlds(pIndex).CheckBox.Value
j = j + 1
With Dialogs(wdDialogFormFieldOptions)
.Name = "Check" & j
.Execute
End With
oFrmFlds(pIndex).CheckBox.Value = oVar
Case wdFieldFormDropDown
oVar = oFrmFlds(pIndex).DropDown.Value
k = k + 1
With Dialogs(wdDialogFormFieldOptions)
.Name = "DropDown" & k
.Execute
End With
oFrmFlds(pIndex).DropDown.Value = oVar
Case Else
'Do Nothing
End Select
Next pIndex
End Sub
 
F

Fumei2 via OfficeKB.com

It is better not to use Select to selct anything. Nor is it needed. Also,
there is no need to go through the Dialog. This does exactly the same thing,
without Selecting anything, nor using Dialogs.

Sub GlobalRenameFormFields()
Dim DocFF As FormFields
Dim aFF As FormField
Dim TextFF As Long
Dim CheckFF As Long
Dim DropFF As Long

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
Set DocFF = ActiveDocument.FormFields

For Each aFF In DocFF
Select Case aFF.Type
Case wdFieldFormTextInput
aFF.Name = "Text" & TextFF + 1
TextFF = TextFF + 1
Case wdFieldFormCheckBox
aFF.Name = "Check" & CheckFF + 1
CheckFF = CheckFF + 1
Case wdFieldFormDropDown
aFF.Name = "DropDown" & DropFF + 1
DropFF = DropFF + 1
Case Else
'Do Nothing
End Select
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top