Excel vba Checkbox Wert Checked setzen
Wie kann man auf eine Checkbox in einer Excel Anwendung per vba Makro Code das Checked oder unchecked setzen.
Lösung
Per Checkbox.OLEFormat.Object.Valeu
ctlCheckbox.OLEFormat.Object.Value = True
|
Code Beispiel
'----< @Loop: optional_Control_Inputs >---- '*Excel Checkboxen Dim ctl As Shape For Each ctl In ws.Shapes If ctl.Type = msoFormControl Then '---< Ist_Namesvariable_mit_Kennung >--- Dim ctlCheckbox As Shape Set ctlCheckbox = ctl
Dim sCheckbox_Text As String sCheckbox_Text = ctl.AlternativeText '< correktur > '*loesche Klammer-Texte wie Vorjahr(VJ) Dim posCheck As Integer posCheck = InStr(1, sCheckbox_Text, "(", vbBinaryCompare) If InStr(1, sCheckbox_Text, "(", vbBinaryCompare) > 0 Then sCheckbox_Text = Mid$(sCheckbox_Text, 1, posCheck - 1) sCheckbox_Text = Trim(sCheckbox_Text) End If '</ correktur >
'-< init >- Dim optChecked As Boolean optChecked = list_Daten.ListColumns(sCheckbox_Text).DataBodyRange(row.Index)
If optChecked = True Then 'Excel Checkbox.child=checked ctlCheckbox.OLEFormat.Object.Value = True Else ctlCheckbox.OLEFormat.Object.Value = False End If '-</ init >-
Application.StatusBar = Now & " " & sCheckbox_Text & "=" & optChecked
'---</ Ist_Namesvariable_mit_Kennung >--- End If Next '----</ @Loop: optional_Control_Inputs >---- |