How to access returned Layer from LayerRange.Combine() in macro

I have a VBA script I am working on in which I collect a number of image layers into a range object. I use the Combine() method which should return a layer object, but I cannot see to set it to a variable for further processing. "pix" variable here is the current image document in this code fragment.

Set myLayers = New LayerRange
' Add layers to range
myLayers.Add pix.Layers.Item("a")
myLayers.Add pix.Layers.Item("b")
myLayers.Add pix.Layers.Item("c")
myLayers.Add pix.Layers.Item("d")
' Combine layers to new layer
Set newLayer = myLayers.Combine()

However newLayer is still nothing. The image still shows layer "a" as the combined layers "a" through "d" in Object Manager. Although "pix" the current document has "a" at index 2  in Items collection:

TypeName(newlayer) returns 'nothing'

TypeName(pix.Layers.Item("a")) returns 'iPaintLayer'

TypeName(pix.Layers.Item(2)) returns 'iPaintLayer'

So the layer seems to be there but cannot be accessed or assign to a variable. If  you try you get a runtime error 'The references object doesn't exist anymore. So how do you combine several layer objects to a single layer object and access it afterwards?

--

Jonathan

Parents
  • Wow! So I get this email announcing that I earned  "Ask A Question I" achievement whatever that means. To be honest I would rather received is information on the problem at hand or at least a pointer towards where I can find some real information on Corel's version of VBA. Google has be failing me here... I have be using CD since version 4 and the scripting not only has changed drastically over that time, but it has always been woefully undocumented and quirky. Yes I know that I am still on X8,  but viewing all the instability issues with 2019 I do no see any compelling reason to upgrade.

    --

    Jonathan

Reply Children