Get Layer by name

Started by TheCykor, May 19, 2016, 08:22:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TheCykor

Hi All!

I am just doing a Visio sheet where I want to dynamically assign Shapes to Layers by
shp.CellsU("layermember").Formula = 1

However what I don't 100% understand the relation betweend Layer names (as Identified in Layer Properties, and the Layer ID (Int) I need to specify for the Shape.

Is there any way to have a "getLayerByName(String Name)" function? which would allow me to do something like
shp.CellsU("layermember").Formula = getLayerByName("hidden")

Thanks

TheCykor

Surrogate

getLayerByName ???It is custom function ?

TheCykor

Hi,

Well it is the function is am looking for, but after some additional hours and tries i got the following (working) code:



Private Function GetLayerIDByName(n As String) As Integer

Dim vsoPage As Visio.Page
Dim vsoShape As Visio.Shape
Dim vsoLayers As Visio.Layers
Dim vsoLayer As Visio.LAYER
   
   Debug.Print "-------- GetLayerIDByName( " & n & " ) ------------"
'MsgBox "In GetLayerIDByname with " & n



If ActiveDocument Is Nothing Then
    Documents.Add ("")
End If

Set vsoPage = ActivePage
    If vsoPage Is Nothing Then
    Set vsoPage = ActiveDocument.Pages(1)
End If

Set vsoLayers = vsoPage.Layers

Debug.Print "--> Overall Count" & vsoLayers.Count
'MsgBox "--> Overall Count" & vsoLayers.Count

For intCounter = 1 To vsoLayers.Count

'    vsoLayer = vsoLayers(intCounter)
objRet = vsoLayers(intCounter)
'MsgBox objRet
If (objRet = n) Then
'   MsgBox "Found" & objRet & "with" & intCounter
   GetLayerIDByName = intCounter - 1
End If



Next intCounter


End Function