Rename multiple controls.

  • Thread starter Thread starter stewart
  • Start date Start date
S

stewart

I have a multipage on a userfrom with 92 optionbuttons. I would like
to change the names from OptionButton1 to opt1. I have seen posts
that includes loops to rename controls but i can find it at the
moment. Any help is appreciated.
 
For a form named "UserForm1" with a multipage named "MultiPage1", you'll need
code like the one below. You will need to enable trust access to Visual
Basic Project (Tools->Macro->Security, in Trusted Publishers tab, check
"Trust access to Visual Basic Project". Also work on a BACKUP copy first to
be safe.


Sub test()
Dim pg As Page
Dim o As Control

For Each pg In
ThisWorkbook.VBProject.VBComponents("UserForm1").Designer.Controls("MultiPage1").Pages
For Each o In pg.Controls
If TypeOf o Is MSForms.OptionButton Then
o.Name = Replace(o.Name, "OptionButton", "opt")
End If
Next o
Next pg

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

Back
Top