CorelDraw

Check if layer exists

Ease of Use

Easy

Version tested with

2005 (X3) 

Submitted by:

malik641

Description:

Tests the passed layer name to see if it exists in the active page. 

Discussion:

When working with layers in CorelDraw, you should check if the layer exists before proceeding. This function will do just that. It will return True if the layer exists, False if it doesn't. 

Code:

instructions for use

			

Public Function LayerExists(ByVal strLayerName As String) As Boolean ' This function will return true if the layer name passed exists Dim objLayer As CorelDRAW.Layer On Error Resume Next Set objLayer = ActivePage.Layers(strLayerName) LayerExists = Not objLayer Is Nothing End Function Public Sub TestMyFunction() Const strBadLayer As String = "This Layer Does Not Exists" Const strGoodLayer As String = "Layer 1" Debug.Print "Testing '" & strBadLayer & "' Layer to see if it exists..." Debug.Print LayerExists(strBadLayer) Debug.Print "Testing '" & strGoodLayer & "' Layer to see if it exists..." Debug.Print LayerExists(strGoodLayer) End Sub

How to use:

  1. In CorelDraw, Press Alt+F11 to open the VBE
  2. Select your GMS (global macro storage) in the Project Window
  3. Click Insert --> Module
  4. Copy code and paste in the new Module
 

Test the code:

  1. In CorelDraw VBE (Alt+F11) Place Cursor inside TestMyFunction procedure
  2. Press F5 to Run procedure
  3. View Results in the Immediate Window (Press Ctrl+G if not visible)
 

Sample File:

TestingLayerExistsFunction.zip 8.41KB 

Approved by mdmackillop


This entry has been viewed 77 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express