I'm trying to write a macro for Photo Paint, but, since there is no recorder and not much documentation, I'm going by trial and error. The problem I'm having is that PP crashes every time I run this macro and try to close the document without saving the changes. Maybe somebody can take a look at it and detect what I'm doing wrong that causes so many crashes.
Code:
Sub IndexSixSimple()
'-----------------------------------------------------------------------------
'Index separations with six basic colors in simple form.
'Macro created by Manuel Rivas. April 2009
'This macro takes either an RGB or CMYK file and separates it in six primary
'colors: Black, White, Yellow, Blue, Red and Green
'-----------------------------------------------------------------------------
Dim Doc As Document, pal As Palette
Dim Blk As Color, Wht As Color, Yel As Color, Red As Color, Grn As Color, Blue As Color
Dim FOpen As String, palpath As String
Dim cm1 As New ColorMask
Dim CRed As Channel
Set Doc = ActiveDocument
If Doc Is Nothing Then
MsgBox "Open File first", vbOKOnly, "There are no open documents"
FOpen = CorelScriptTools.GetFileBox("Bitmap Files (*.bmp; *.jpg; *.tif; *.cpt; *.psd)|*.bmp; *.jpg; *.tif; *.cpt; *.psd", _
"Open File")
End If
If FOpen <> "" Then
Set Doc = Application.OpenDocument(FOpen)
Else
If Doc Is Nothing Then
Exit Sub
End If
End If
Set pal = Palettes.Create("Six Simple", , True)
palpath = pal.FileName
Set Blk = CreateColorEx(2, 0, 0, 0, 100)
Set Wht = CreateColorEx(2, 0, 0, 0, 0)
Set Yel = CreateColorEx(2, 0, 0, 100, 0)
Set Red = CreateColorEx(2, 0, 100, 100, 0)
Set Grn = CreateColorEx(2, 100, 0, 100, 0)
Set Blue = CreateColorEx(2, 100, 28, 0, 0)
With pal
.AddColor Blk
.AddColor Wht
.AddColor Yel
.AddColor Red
.AddColor Grn
.AddColor Blue
End With
Doc.ConvertToPaletted cdrPaletteCustom, cdrDitherJarvis, 100, , , , , , , , , palpath
With cm1
.AddColor Red
.Threshold = 1
.Inverted = True
End With
Set CRed = Doc.Channels.AddFromColorMask(cm1, "Red", 100, Red)
End Sub