Hello,
I have a few different macros running in my set-up but I keep getting road-blocked by a Find and Replace Macro. I need a macro that finds one color, say Yellow, and replaces it with another, say Red. Seems simple. I've recorded it and it works flawlessly, as long as the shapes it's replacing are the same for every design on the page. But as soon as I try to run the same macro on a different design, it fails saying:
"Run-Time error '-2147024809 (8000700057)':
Parameter Index is out of range. It's Value must be between 1 and 0.
Then I debug and it seems the error is that even though the macro was recorded to Find and Replace All, it's only recording the actual shape that was replaced. So if I recorded the macro and there was only one shape on the page that was yellow, it turns it to red just fine. But, if I have two or more shapes on the page, it crashes.
Is there a way to record, or code, a "Find All" yellow shapes on the page and "Replace All" with another color. I can see in my other macros that you can record "Ctrl A" for Select All, but I can't find a way to record a Find All or Replace All.
This might help. Just need to code your specifics in place of these colors
Sub ConvertYellows() ActiveDocument.BeginCommandGroup "ConvertYellows" Dim sr As ShapeRange Set sr = ActivePage.Shapes.FindShapes(Query:="@fill.color.cmyk[.c=0 and .m=0 and .y=0 and .k=100]") sr.AddToSelection sr.ApplyUniformFill CreateRGBColor(0, 0, 0) ActiveDocument.EndCommandGroupEnd Sub
Thanks! That works!
So this macro is something that has to physically written, it can't be "recorded" in steps right?
Mine looks like this. I added a Paste>Move>Copy command. It works great:
Sub ConvertYellows()
ActiveDocument.BeginCommandGroup "ConvertYellows"
Dim sr As ShapeRange
Set sr = ActivePage.Shapes.FindShapes(Query:="@fill.color.rgb[.r=255 and .g=234 and .b=0]")
sr.AddToSelection
sr.ApplyUniformFill CreateRGBColor(235, 5, 12)
ActiveDocument.EndCommandGroup
Dim pasteopt As StructPasteOptions
Set pasteopt = CreateStructPasteOptions
With pasteopt.ColorConversionOptions
.SourceColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%"
.TargetColorProfileList = "sRGB IEC61966-2.1,U.S. Web Coated (SWOP) v2,Dot Gain 20%"
End With
Dim Paste1 As ShapeRange
Set Paste1 = ActiveLayer.PasteEx(pasteopt)
Paste1.Move 9.4, 0#
Paste1.Copy
End Sub
Now how would I add another color change to that?
Right now I'm copying the yellow colored shape, then I run the macro which changes the color to red, pastes the yellow, nudges it and copies it. I tried adding the "ConvertYellow" code (with a different color change) to the end of mine, but it fails once I. do that. Can you not run more that one CommandGroup in a macro?
I use Macro (Color Replacer X8-2018 Black-V3) I have no problems, it is very good.is this the one you use?
https://www.corelnaveia.com/2018/02/color-replacer-coreldraw-x8-e-2017.html
I don't use this. Just regular record and replicate. I don't speak Portuguese unfortunately. Will that program work on CorelDraw 2020 64bit?
yes