Code to Change Command Button Name
Posted on 2007-07-23
I'm using the following code that was provided by GrahamSkan:
Dim ilsh As InlineShape
Dim i As Integer
For Each ilsh In ActiveDocument.InlineShapes
If ilsh.OLEFormat.ClassType = "Forms.CommandButton.1" Then
i = i + 1
ilsh.OLEFormat.Object.Name = "CB" & i
This code used to work, but now I'm getting the following error:
Run-time error '-2147319764 ...
Method 'Name' of object 'ICommandButton' failed
I'm using the code in a macro in a Word 2003 file. Basically, I want to loop through all the ActiveX command buttons in a file and change their names. The first button needs to be named CB1, the second needs to be CB2, etc.