OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-09-2004, 19:26
D_Green
Guest
 
Posts: n/a
Default Wish to Convert Named Colors to Shape Color

During importation of data (via VBA macros) I need to create shapes in specific colors as defined by pre-generated data. These colors are generated at textual colors eg color imported as "Green", "Red", "Black" etc.

The shapes (rectangles, ellipses, text) are easily created but previous methods by settings colors has been:

Select Case Color
Case "Black"
ActiveShape.Fill.UniformColor.RGBAssign 0, 0, 0
Case "Blue"
ActiveShape.Fill.UniformColor.RGBAssign 0, 0, 255
Case "Red"
ActiveShape.Fill.UniformColor.RGBAssign 255, 0, 0
|
|
(and so on)
End Select

This method was ok when 2 colors were initially introduced but has become to cumbersome with greater number of colors being used and also having to know colors prior for inclusion to above method (so macro can be updated to accommodate new color).

Is there a methodology to utilise the "color" directly. I have tried several ways but with no success.

I look forward to any help that may come this way.

Best Regards,
Denis
Reply With Quote
  #2  
Old 12-09-2004, 11:08
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Wish to Convert Named Colors to Shape Color

Denis,

You can look through colors in the current palette and find the color by its name. You just need to open the proper palette that contains the colors that you have and set it as a default palette.

Here is a function that finds a color by its name in the current palette and returns the color found:

Code:
Function GetColorByName(ByVal Name As String) As Color
    Dim cRet As Color
    Dim c As Color
        
    Set cRet = Nothing
    For Each c In ActivePalette.Colors
        If c.Name = Name Then
            Set cRet = c
            Exit For
        End If
    Next c
    
    If cRet Is Nothing Then
        MsgBox "Color '" & Name & "' is not found. Using black", vbExclamation
        Set cRet = CreateCMYKColor(0, 0, 0, 100)
    End If
    
    Set GetColorByName = cRet
End Function
Here is how you can use the function to apply a specific color to an object:

Code:
Sub TestColor()
    ActiveShape.Fill.ApplyUniformFill GetColorByName("Ice Blue")
End Sub
I hope this is what you are looking for...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
activeselection cloning s_federici CorelDRAW/Corel DESIGNER VBA 2 05-11-2004 09:59
Retrieve Color Values from Selected Object Jon Lorber CorelDRAW/Corel DESIGNER VBA 2 19-08-2004 07:24
Finding Color Currently Selected in RGB or CMYK Palette AARRGGHHH CorelDRAW/Corel DESIGNER VBA 1 30-03-2004 09:03
Convert barcode to curves pp21 New product ideas 1 10-03-2004 22:56
Selecting Obejcts with the same color - PLease help Superfreak CorelDRAW/Corel DESIGNER VBA 3 19-03-2003 21:31


All times are GMT -5. The time now is 10:13.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com