VBA code to modify the (Name) property of an ActiveX Command Button

Hello,

I have a Word 2010 Macro enabled document that contains two sets of ActiveX Command Buttons.  One set of buttons performs a spell check on specific sections of the document and then prints those same sections.  The other buttons add new pages to the document.

During the month of November, all the buttons worked perfectly.  During December, Microsoft applied an MS Office Security Update (KB2553154) which disabled all of my AxtiveX Command Buttons.  I have since learned at this site, thanks to Suzanne S. Barnhill , that Microsoft has created a workaround for this issue KB3025036 .  Our IT staff has applied the workaround to the necessary PCs.

After applying the workaround fix, most of the command buttons work again, but some of them don’t.  In researching the problem, I discovered that the  (Name) Property for the buttons that are not working has been changed, thus when clicking on the button, the macro cannot be located because it has a different name than the button does.

For example, in one instance the original button (Name) was Print_Intake_Form, but the (Name) has now been changed to Print_Intake_Form1.  In another instance, the original button (Name) was Print_Intake_Form, but the (Name) has now been changed to Print_Intake_Form11. 

My idea for fixing this issue would be to create a macro that modifies the (Name) property for all the ActiveX buttons back to their original names.  If that seems like the best way to fix the issue, what VBA code woudl be needed to perform such a task?

If that is not the best way to resolve the issue, I am open to suggestions.

Thank you

Mark
Answer
Answer

I'll make the assumption that all your command buttons originally had names that did not end in any digits, and that the code attached to those buttons retained the original names, so the fix consists of removing any digits that occur at the end of command button names. If that assumption isn't correct, post back and explain what the macro needs to do.

If the assumption is correct, this macro should fix one entire document. It could be modified to make it fix all the documents in a particular folder, or a folder and all its subfolders, if that's necessary.

Sub FixActiveXButtons()
    Dim shp As InlineShape
    Dim strName As String
    
    For Each shp In ActiveDocument.InlineShapes
        On Error GoTo Skip_it
        If shp.OLEFormat.ClassType = "Forms.CommandButton.1" Then
            strName = shp.OLEFormat.Object.Name
            While IsNumeric(Right(strName, 1))
                strName = Left(strName, Len(strName) - 1)
            Wend
            shp.OLEFormat.Object.Name = strName
Skip_it:
        End If
    Next
End Sub

_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated September 30, 2021 Views 1,819 Applies to: