Search code examples
vbacoreldraw

Selecting layer to search on all pages


This is part of the code im working with;

Dim s As Shape

Dim p As Page, numberPage As Integer
Dim i&

Dim WhatSamp As String

WhatSamp = "Sample1"

For i = 1 To ActiveDocument.Pages.Count
ActiveDocument.Pages(i).Activate

For Each s In ActiveDocument.ActivePage.Shapes

If s.Type = cdrTextShape Then

     If InStr(1, s.Text.Story, WhatSamp) > 0 Then
     ActivePage.Layers("Sample").Visible = True
     ActivePage.Layers("Sample").Printable = True

     End If

End If

Next

Next i

The code im working with is much longer but i believe this is the relevant part.

It searches for my text on the page (Sample1) then displays and makes printable the layer called "Sample".

I think because I have a ridiculous amount of needed layers it takes forever to run

So, Im trying to get it to search for my text only on a specific layer that exists on each page called "Style" but i cant seem to figure it out.

Thank you in advance.

Let me know if more information is needed


Solution

  • To test on what layer is object "S" use if

     if S.Layer.Name="Style" then
    

    then

    If InStr(1, s.Text.Story, WhatSamp) > 0 Then
     ActivePage.Layers("Sample").Visible = True
     ActivePage.Layers("Sample").Printable = True