Change multiple object group name

  • Thread starter Thread starter GreenBean
  • Start date Start date
G

GreenBean

Hi all,

Whilst the code below changes all button names from GW2opt to GW4opt is
there a way to change group names e.g. change group 1a to 1a4 but using a
wildcard char to replace 1a since I have groups 1b, 1c, etc. Simply, Iwant
to add 4 to all group names!

Public Sub ChangeButtonName()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
With OleObj
.Name = Replace(.Name, "GW2opt", "GW4opt")

End With
Next OleObj
End Sub
 
Public Sub ChangeButtonName()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
With OleObj.Object
.GroupName = Replace(.GroupName, .GroupName, .GroupName & "4")
End With
Next OleObj

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Bob Phillips said:
Public Sub ChangeButtonName()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
With OleObj.Object
.GroupName = Replace(.GroupName, .GroupName, .GroupName & "4")
End With
Next OleObj

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
Hi Bob,

I've tried the scipt and it doesn't like it - get run time error 438...I
tried something similar but with same outcome....
 
GreenBean said:
Hi Bob,

I've tried the scipt and it doesn't like it - get run time error 438...I
tried something similar but with same outcome....
Sri Bob - tell a lie - it works once - didn't see the change first
time!!!ooops

Is there a way to use wild card since if I want to change 1a4 to 1a5 the
scipt will currently give 1a44?

tia
 
Public Sub ChangeButtonName()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
With OleObj.Object
.GroupName = Left(.GroupName,len(.GroupName)-1) & "5"
End With
Next OleObj

End Sub
 
Tom Ogilvy said:
Public Sub ChangeButtonName()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
With OleObj.Object
.GroupName = Left(.GroupName,len(.GroupName)-1) & "5"
End With
Next OleObj

End Sub
Sorry Tom - didn't work first time then did! Must be losing it tonight.
Both now work but always end in runtime error 439 - object not supported -
is there a way to fix that?
 
This worked fine for me:

Public Sub ChangeButtonGroupName()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
If TypeOf OleObj.Object Is MSForms.OptionButton Then
With OleObj.Object
.GroupName = Left(.GroupName, Len(.GroupName) - 1) & "5"
End With
End If
Next OleObj

End Sub
 
Tom Ogilvy said:
This worked fine for me:

Public Sub ChangeButtonGroupName()
Dim OleObj As OLEObject

For Each OleObj In ActiveSheet.OLEObjects
If TypeOf OleObj.Object Is MSForms.OptionButton Then
With OleObj.Object
.GroupName = Left(.GroupName, Len(.GroupName) - 1) & "5"
End With
End If
Next OleObj

End Sub
thx Tom - working great now....
 

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