I started this many years ago but now I am changing it up to make it flow a little better. I have a form that you can select different sizes for bleed settings both inside and outside a page space. I want to check to see if the bleed lines layer has been created already. If so you do have an option to continue and create another set or cancel and keep the one that's there. That would happen in this first portion of code before loading the bleed form. The section below that is the code for the form itself plus the form.
The code I have to call out the form for the first step.
You might look at the Layers.Find method in the CorelDRAW API documentation.
Here's an example where I check to see if a page layer named, "foo" exists:
Sub check_page_layer_foo_exists() Dim layThis As Layer Set layThis = ActivePage.Layers.Find("foo") If Not layThis Is Nothing Then MsgBox "The page layer ""foo"" exists." Else MsgBox "The page layer ""foo"" does not exist." End If End Sub
You don't really need to create an object to do that, either. I did that to explicitly show that Layers.Find was expected to return a Layer.
You could just do something like this:
Sub check_page_layer_foo_exists_2() If Not ActivePage.Layers.Find("foo") Is Nothing Then MsgBox "The page layer ""foo"" exists." Else MsgBox "The page layer ""foo"" does not exist." End If End Sub
Instead of using ActivePage.Layers to check just for page layers, you could use ActiveDocument.MasterPage.Layers to limit it to master layers, or ActivePage.AllLayers to check both page layers and master layers.
You could also wrap up the capabilities you need into a function in VBA.