Programatically edit command button properties of all command buttons

Started by crtausche, March 23, 2020, 06:07:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

crtausche

I have some sample code which works well for all shapes on an active page, and I am wondering about adjusting it to work with command buttons. The code is pasted below.

Sub Shapes()

    utsInput = ComboBox1.Value

    Dim vsoShapes As Visio.Shapes

    Set vsoShapes = Application.ActivePage.Shapes
    For Each shp In vsoShapes
        If shp.CellExistsU("Prop._VisDM_Unmanaged_Tunnel_Slot", 1) Then
            Dim cell As Visio.cell
            Set cell = shp.CellsU("Prop._VisDM_Unmanaged_Tunnel_Slot")
            cell.FormulaU = Chr(34) & utsInput & Chr(34)
        End If
    Next

End Sub



I want to apply the same logic but for command buttons, and instead of just setting a shapesheet cell value I want to edit the commandbutton properties. For instance, commandbutton1.Enabled = False. (or true depending on conditions)

I would like to apply this to all pages within a document, since numerous pages have command buttons. I guess I am need to figure out where commandbuttons properties lives within the object browser.

I apologize if this question was already answered somewhere or this is not in the right location, but I did not see this question posted anywhere.

OldSchool1948

Try this.   

Private Sub setObjectProperties()
               
    Dim Obj As Object
    For Each Obj In ThisDocument.OLEObjects
               
        With Obj
            .Object.Enabled = True
        End With
       
    Next Obj

End Sub


Step though the code in the debugger and look at all of the properties in Obj.Object to see what you can set.  Use the ClassID value to determine the type of object, i.e;. Label, TextBox, ComboBox, CommandButton, CheckBox, etc.  This is important if you want to set .Value or .Caption or other properties.

'The ActiveX control uses following CLSIDs:
'{8BD21D40-EC42-11CE-9E0D-00AA006002F3} - Microsoft Forms 2.0 CheckBox
'{8BD21D50-EC42-11CE-9E0D-00AA006002F3} - Microsoft Forms 2.0 OptionButton
'{8BD21D60-EC42-11CE-9E0D-00AA006002F3} - Microsoft Forms 2.0 ToggleButton
'{8BD21D30-EC42-11CE-9E0D-00AA006002F3} - Microsoft Forms 2.0 ComboBox
'{8BD21D10-EC42-11CE-9E0D-00AA006002F3} - Microsoft Forms 2.0 TextBox
'{D7053240-CE69-11CD-A777-00DD01143C57} - Microsoft Forms 2.0 CommandButton

wapperdude

Expanding upon the above code, this time, page referenced  The code searches all OLE objects on the page, gets the typeName, e.g., ComboBox, CkBox, and then uses CASE construct to specify the type of object and set features specific to that type.  Only single case shown to illustrate the idea.


Sub whoAmI()
    Dim vShp As Visio.Shape
    Dim oObj As Visio.OLEObject
    Dim spObj1 As Visio.OLEObject
    Dim spObj2 As Visio.OLEObject
   
    For Each oObj In ActivePage.OLEObjects
        With oObj
            objName = TypeName(.Object)
            Select Case objName
                Case Is = "ComboBox"
                    Debug.Print TypeName(.Object)
                    With .Object
                        .BackColor = RGB(200, 200, 255)
                        .Font.Name = "DomCasual BT"
                        .Font.Size = 12
                        .AutoSize = True
                        Debug.Print .Name
                    End With
            End Select
        End With
    Next
   
End Sub


Visio 2019 Pro