Hi all, new here, and have found so many qusetions answered here and Oberon - thank YOU. I do have a question though.
I have a toolbar with macros to open and close different palettes. Each palette represents a type of fabric. The company I work for has certain colors in certain fabrics, so in order to restrict the user from choosing a color we don't have, we thought we would have a different palette for each fabric (yes, it could get out of hand with the number of palettes).
What I want to do is track the active shape/curve on the document, and then the color that is active/selected on the palette. Or maybe a palette_OnClick as my access mind would think. Through that, I can query against a database and get information that I would like to store in the ObjectData of the shape, specifically a MaterialID.
I have tried phrasing this all sorts of different ways in Google and am not finding solutions. ActiveColor on the Palette, OnClick of Palette, "Color Clicked"
Let me know what you guys think!
It might help to play out a bit how you would want this to work, in practice.
So, for example, you're working in CorelDRAW, and have VBA code that runs whenever the SelectionChange event fires (which includes selecting an item or changing its fill or outline color).
What do you want to do when that event fires?
Wow, I didn't realize SelectionChange existed. I see how that works, generally. I see that I can capture the color being selected from the palette.
I am having a problem retrieving the ObjectData for the object that triggered the SelectionChange. For instance, I CTRL+click an object, and can get the color, but the ObjectData("Name") doesn't seem to return.
Here's what I have, please forgive me for struggling to format in this little response box.
Private Sub GlobalMacroStorage_SelectionChange() Dim s As Shape Dim c As ColorIf ActiveSelection.Shapes.Count = 0 Then Exit Sub Else Set s = ActiveSelection If s.Shapes.Count > 0 Then Set c = s.Fill.UniformColor Debug.Print s.ObjectData("Name") Debug.Print c.Name End If End IfEnd Sub
When I do that sort of thing, I usually have something like this in "ThisMacroStorage":
Private Sub GlobalMacroStorage_SelectionChange()
and then have it call a sub in another module in the project:
Dim sr As ShapeRange
Dim s As Shape
Dim colorThis As Color
Dim strObjDataName As String
If Not ActiveDocument Is Nothing Then
If ActiveSelectionRange.Count = 1 Then
Set s = ActiveSelectionRange(1)
If s.Type = cdrCurveShape Then
If s.Fill.Type = cdrUniformFill Then
Set colorThis = s.Fill.UniformColor
strObjDataName = s.ObjectData("Name")
Debug.Print "Object Data Name: " & strObjDataName
Debug.Print "Color name: " & colorThis.Name
I don't get a value for ObjectData("Name") unless I have deliberately set the name to something other than the default name that was assigned to the object when it was created.
That is so cool! Thank you very much! Game changer for sure.
I'm glad to know that was helpful.
I use SelectionChange to make userforms "responsive" to the current selection. You can find some macros that do that in my blog: Eskimo's Macros and More.
I always try to be careful with how I use it, because that event fires really, really often!