![]() |
#1
|
|||
|
|||
![]()
I am running CD X3, MS Excel 2003, XP, SP2
I have created the macro and it runs successfully. It reads the Pantone Corel 8 palette and writes all the Pantone names and numbers, along with the CYMK and RGB equivalents into the Excel spreadsheet. I have some questions and would also appreciate comments on the code. 1. The only way I could get this to work was to have a CD document with one shape on it when I started the macro. Is there an option? 2. It seems like it runs slowly -- is that my code? 3. PANTONE Trans. White CV shows up multiple times in the list -- it always has an index number of 952, but the CYMK and RGB equivalents are different each time. Any idea what's going on? 4. There are gaps in the Pantone index numbers. Is that an issue? Code:
Sub ListColorInfo() '==================================================================================== ' Date: 04/11/07 ' Author: Judy Hudgins ' Purpose: This procedure reads the Pantone Corel 8 palette and creates an Excel ' spreadsheet with the index value, the Pantone color, the CYMK value, ' and the RGB value '==================================================================================== Dim XLSheet As Object Dim XLApp As Object Dim colColor As Color Dim colDupe As New Color Dim palPalette As Palette Dim lngCount As Long Dim strPantone As String Dim strCYMK As String Dim strRGB As String Dim strTitle As String '==================================================================================== ' Delete existing spreadsheet ' err.number 53 will occur if the file does not already exist ' err.number 70 will occur if the file is open in Excel '==================================================================================== strTitle = "Pantone, CMYK, RGB List" On Error Resume Next Kill "c:\pantone.xls" If Err.Number = 53 Then 'continue process ElseIf Err.Number = 70 Then MsgBox "Excel file is open" & vbCrLf & "Process Cancelled", vbOKOnly + vbExclamation, strTitle Exit Sub End If '==================================================================================== ' Set Environment and variables '==================================================================================== Set XLSheet = CreateObject("Excel.sheet") Set XLApp = XLSheet.Application lngCount = 0 '==================================================================================== ' Write Spreadsheet Headings '==================================================================================== With XLApp.activesheet.pagesetup .printtitlerows = "$1:$2" .CenterHeader = "&""Arial,bold""&Pantone Corel 8, CYMK, RGB" .RightHeader = "Revised: &D" .LeftFooter = "&T" .RightFooter = "Page &P of &N" .Orientation = 2 .LeftMargin = XLApp.InchesToPoints(0) .RightMargin = XLApp.InchesToPoints(0) End With With XLApp.Range("C:C") .HorizontalAlignment = -4131 .VerticalAlignment = -4107 End With '==================================================================================== ' Write Column Headings '==================================================================================== XLApp.Range("a1").Select XLApp.ActiveCell.formular1c1 = "Index" XLApp.Selection.Font.FontStyle = "Bold" XLApp.Range("b1").Select XLApp.ActiveCell.formular1c1 = "Pantone" XLApp.Selection.Font.FontStyle = "Bold" XLApp.Range("d1").Select XLApp.ActiveCell.formular1c1 = "CYMK" XLApp.Selection.Font.FontStyle = "Bold" XLApp.Range("f1").Select XLApp.ActiveCell.formular1c1 = "RGB" XLApp.Selection.Font.FontStyle = "Bold" '================================================================================== ' Check to see if Pantone Corel 8 palette is open. If not, open it '================================================================================== For Each palPalette In Palettes If palPalette.Type = cdrFixedPalette Then If palPalette.PaletteID = cdrPANTONECorel8 Then Exit For End If End If Next palPalette If palPalette Is Nothing Then Set palPalette = Palettes.OpenFixed(cdrPANTONECorel8) End If '================================================================================== ' Loop through Pantone Color 8 palette and print color name, CYMK and RGB ' equivalent '================================================================================== For Each colColor In palPalette.Colors ActiveShape.Fill.UniformColor = colColor 'Convert to CYMK colDupe.CopyAssign ActiveShape.Fill.UniformColor colDupe.ConvertToCMYK strCYMK = colDupe.Name(True) 'Convert to RGB colDupe.CopyAssign ActiveShape.Fill.UniformColor colDupe.ConvertToRGB strRGB = colDupe.Name(True) lngCount = lngCount + 1 ' Write to spreadsheet XLApp.ActiveCell.Offset(rowoffset:=1, columnOffset:=-5).Activate XLApp.ActiveCell.formular1c1 = colColor.PaletteIndex XLApp.ActiveCell.Offset(rowoffset:=0, columnOffset:=1).Activate XLApp.ActiveCell.formular1c1 = colColor.Name XLApp.ActiveCell.Offset(rowoffset:=0, columnOffset:=2).Activate XLApp.ActiveCell.formular1c1 = strCYMK XLApp.ActiveCell.Offset(rowoffset:=0, columnOffset:=2).Activate XLApp.ActiveCell.formular1c1 = strRGB XLApp.ActiveCell.Offset(rowoffset:=1, columnOffset:=-5).Activate Next colColor '==================================================================================== ' Format Columns '==================================================================================== XLApp.Range("A:A").Select XLApp.Selection.EntireColumn.AutoFit XLApp.Range("B:B").Select XLApp.Selection.EntireColumn.AutoFit XLApp.Range("C:C").Select XLApp.Selection.EntireColumn.ColumnWidth = 5 XLApp.Range("D:D").Select XLApp.Selection.EntireColumn.AutoFit XLApp.Range("E:E").Select XLApp.Selection.EntireColumn.ColumnWidth = 5 XLApp.Range("F:F").Select XLApp.Selection.EntireColumn.AutoFit '==================================================================================== ' Save Spreadsheet '==================================================================================== XLSheet.SaveAs "C:\pantone.xls" MsgBox "Found " & lngCount & " colors" End Sub |
#2
|
||||
|
||||
![]()
Judy,
First, you are using a shape to convert the pantone color to CMYK and RGB: Code:
ActiveShape.Fill.UniformColor = colColor colDupe.CopyAssign ActiveShape.Fill.UniformColor Code:
colDupe.CopyAssign colColor |
#3
|
|||
|
|||
![]()
Thanks, Alex. I appreciate the feedback. I made the changes, and it worked great.
|
#4
|
||||
|
||||
![]()
Hi Judy,
To answer #2, I say it is most likely your code that is making things a little slow. For example, using .Select and .Activate for Excel VBA slow down code pretty well. Also using a lot of OLE references (the dot between the words in code) will slow you down some as well. If you can use With --- End With statements I would recommend doing so. There's a very nice article about how to optimize Excel VBA code here if you would like to have a look. Quote:
Code:
With XLSheet .Range("A1").Value = "Index" .Range("B1").Value = "Pantone" .Range("D1").Value = "CYMK" .Range("F1").Value = "RGB" .Range("A:B,D:D,F:F").Font.FontStyle = "Bold" End WIth Quote:
Code:
' Write to spreadsheet lngCount = lngCount + 1 ' If you used my code above, you will still be in cell "A1" ' Using Cells(Row,Column) will be very useful using the lngCount ' that you have here. With XLSheet .Cells(lngCount + 1, "A").Value = colColor.PaletteIndex .Cells(lngCount + 1, "B").Value = colColor.Name .Cells(lngCount + 1, "D").Value = strCYMK .Cells(lngCount + 1, "F").Value = strRGB End With Quote:
Code:
XLSheet.Range("A:B,D:D,F:F").EntireColumn.AutoFit XLSheet.Range("C:C,E:E").EntireColumn.ColumnWidth = 5 Quote:
Code:
XLApp.Quit Set XLSheet = Nothing Set XLApp = Nothing I hope this will help you. I know it's been a while since there has been a post here, but this will surely make your code run faster. |
#5
|
|||
|
|||
![]()
Thank you so much for the very useful feedback. That's exactly the type of information that I am looking for. I appreciate your time.
Judy |
#6
|
|||
|
|||
![]()
I'm just glad you checked it!
![]() And I'm glad you find it useful. If you have any more questions regarding Excel VBA, I'm more than happy to help (I do a lot more Excel VBA than CorelDraw VBA, fyi). |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cannot use Curveworks macros in a user witten macro??? | jon46089 | CurveWorks | 2 | 02-03-2006 14:18 |
Help with Replace Macro | Pumpkin_Masher | Macros/Add-ons | 1 | 21-09-2005 14:41 |
An Idea for a handy and easy to make macro | vallentin | Macros/Add-ons | 2 | 16-03-2004 11:35 |
New macro to clip curves w.r.t. a border | Gerard Hermans | Macros/Add-ons | 0 | 09-06-2003 07:50 |
Speeding up a macro | Rick Randall | CorelDRAW/Corel DESIGNER VBA | 2 | 12-12-2002 10:51 |