Hi.
So, let me try to explain my problem.
I have a Group (28 to be exact) of Rectangle Shapes that are labled "cb1s", "cb1n", cb2s", cb2n".If the Shape has a fill the value is true and if not it's false.
Now, I have a form with CheckBox that have the same names.
Without doing a "If Then Else" for each Shape and CheckBox, is there a way to do it.
I'm attaching a sample Doc from CorelDRAW 2019 with the VBA form Embedded.
Any help would higly apreciated.
I'm not sure I understand what you actually want to do.
Are you trying to use checkboxes in a userform to modify the drawing, e.g., set the fill properties of the rectangles in the drawing?
If that's what you are doing, then I think you would need one checkbox in the form for each Yes/No pair of rectangles.
That's exactly what I'm trying to do.
And I have one CheckBox for each Rectangle.
In the example I only have 12.
Added two buttons to form to get fills to checkboxes and to set fills.
Private Sub cbSet_Click()
Dim cnt As Variant, s As Shape
For Each cnt In Me.Controls
If TypeName(cnt) = "CheckBox" Then
Set s = ActivePage.Shapes.FindShape(cnt.Name)
If Not s Is Nothing Then
If cnt.Value Then
s.Fill.UniformColor.CMYKAssign 0, 0, 0, 100
Else
s.Fill.ApplyNoFill
End If
Next cnt
End Sub
Private Sub cbGet_Click()
If s.Fill.Type <> cdrNoFill Then cnt.Value = True
Private Sub UserForm_Initialize()
ActiveDocument.Pages(1).Activate
ShapeIsThere
cbGet_Click
Thank you very much for helping.
Your code is much cleaner and works better than mine.
Yesterday I was working on this code for applying the CheckBox values but was working really weird:
Sub Set_ShapesProps() ActiveSelectionRange.RemoveAll ActiveLayer.Shapes.FindShape("PropLocal").AddToSelection Dim sg, s As Shape Dim sr As ShapeRange Dim sn, sv As String Dim vs As Boolean ' Get's the Shape number Dim si As Long si = 1 Dim ts As String Set sr = ActiveSelectionRange sr.Ungroup Dim ctrl As Control For Each ctrl In Me.Form1.Controls ' Me.Controls If TypeName(ctrl) = "CheckBox" Then ts = CStr(Me.ActiveControl.Name) 'Caption If ctrl.Value = True Then ActiveSelection.Shapes.FindShape(ts).Fill.ApplyUniformFill CreateCMYKColor(0, 0, 0, 100) Else ActiveSelection.Shapes.FindShape(ts).Fill.ApplyNoFill End If End If Else Next ctrl End If Next ctrl End Sub
Again, thank you very much.
Just asking, why did you use Variant for the Control?
There was a type mismatch error in my test code. I think it was because of a collision of VGCore.Control and MSForms.Control. I was too lazy to remember the right type, so I used the Variant. I could also use an Object type or disable the Option Explicit. The best way is to use MSForms.Control, imho.