In VBA, is there a way to copy a CMYK color value from an object to a Dim and convert that value to RGB without effecting the original object's color?
I'm making a macro that copies text from CorelDraw into a Word document and retains as much formatting as possible (font, size, alignment, etc). In order to copy the colors in the text over to Word they first have to be converted from CMYK to RGB. When I use: s.Text.Story.Range.Fill.UniformColor.ConvertToRGB on my text object the individual letter colors are lost and it all becomes the same color (i.e. if the first letter is green and a couple words are yellow, after ConvertToRGB all the text becomes green).
Within the macro (it's too long and complicated to post in this box) there is a loop that goes through each letter in each textbox, getting (from CorelDraw) and setting (In Word) various formatting attributes. I can add ConvertToRgb on each character in the loop and this will retain individual letter colors, but for a few reasons I want to avoid this. Mainly, I don't want this process altering the original CorelDraw document.
I'm wondering if there is a way to convert the color value instead of converting the shapes color.
Any help is greatly appreciated.
Create a variable that can hold a color then convert that instead of the shapes color:
Dim s As Shape Dim c As New Color Set s = ActiveShape c.CopyAssign s.Fill.UniformColor c.ConvertToRGB
Hope that helps,
-Shelby
There is a Function to Match Colors in a Palette. The following creates the CMYK Color of Yellow, and then matches it to the closest color in the Active Palette. It then returns a message box with the index number of the color in the palette and its name.
Sub PaletteMatchColor() Dim pPalette As Palette Dim cColor As Color Dim i As Integer Set pPalette = ActivePalette Set cColor = CreateCMYKColor(0, 0, 100, 0) cColor.ConvertToRGB i = pPalette.MatchColor(cColor) MsgBox "Index: " & i & ", Name:" & pPalette.Color(i).Name End Sub
Best of luck,
Shelby, I see the match palette commands, are these for the document palette or the default application palette?
I am also wondering if conversion commands can work from the 3 document color spaces?
Not trying to be a PITA but if the latter commands are possible a conversion macro may be of use to me.
You may use any palette you wish. If you wanted to use the Document Palette you change the code to this:
Sub DocumentPaletteMatchColor() Dim pPalette As Palette Dim cColor As Color Dim i As Integer Set pPalette = ActiveDocument.Palette Set cColor = CreateCMYKColor(0, 0, 100, 0) i = pPalette.MatchColor(cColor) MsgBox "Index: " & i & ", Name:" & pPalette.Color(i).Name End Sub
As for your second question about the 3 document color spaces you will need to be a little more specific. To be honest I am color stupid. Happy to help figure it out, I will just need a little more explanation. If you want to contact me privately on the forum I am sure we can get it figure out.