Share via

export layer information in Visio

Anonymous
2012-08-30T13:45:50+00:00

Is it possible to export Layer information to excel or someother form from a Visio diagram.

I would ideally like to the objects text, and the layer(s) it is on.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2012-09-02T21:15:53+00:00

    In VBA, insert a UserForm (you can then delete it if you want to) because it will add a reference the DataObject.

    (I'm too lazy to work out which library you need).

    Copy and past the sub function below ...

    You will end up with text in your clipboard that can be pasted into Excel into rows and columns.

    Public Sub ListShapesOnLayers()

    Dim pag As Visio.Page

    Dim sel As Visio.Selection

    Dim shp As Visio.Shape

    Dim dataObj As DataObject

    Dim text As String

    Dim lyr As Visio.Layer

        text = "Page" & vbTab & "Layer" & _

             vbTab & "ID" & vbTab & "Name" & _

                            vbTab & "Text"

        For Each pag In ActiveDocument.Pages

            If pag.Type = visTypeForeground Then

                'Debug.Print pag.Name

                For Each lyr In pag.Layers

                    'Debug.Print , lyr.Name

                    Set sel = pag.CreateSelection(visSelTypeByLayer, 0, lyr)

                    If sel.Count > 0 Then

                        For Each shp In sel

                            If Len(shp.Characters.text) > 0 Then

                                text = text & vbCrLf & pag.Name & vbTab & lyr.Name & _

                                    vbTab & shp.ID & vbTab & shp.Name & _

                                    vbTab & shp.Characters.text

                            End If

                        Next

                    End If

                Next lyr

            End If

        Next

        Set dataObj = New DataObject

        dataObj.Clear

        dataObj.SetText text

        dataObj.PutInClipboard

        MsgBox "Paste the text into Excel or somewhere", vbInformation

    End Sub

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2012-09-02T21:24:20+00:00

    I should also remind you that shapes in Visio do not have to be on a lyer, and they can be assigned to multiple layers. Therefore, it is possible that the same shape is reported on more than one layer in the code above.

    Was this answer helpful?

    0 comments No comments