BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Auto draw network topology from excel data import

Started by seven80, August 27, 2016, 10:38:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


It is possible to create automatically a complete network topology from an excel file?
In my excel I have devices and connections information.
I imported all data in visio but now I only can link external data to a shape and manually connect the device shape with others.
My network is a bit large and I would like avoid to connect manually all the devices.


Thanks but I didn't found how to create automatically connection between shapes.
From external data I have also the connections information in a column defined "link to".
Can I automatically connect the imported shapes each others?


Long ago, when computers were big and programs were small, Visio supported creating diagrams from excel, like you describe (Visio 5, I believe?).
But those days are gone.

As of my knowledge, the last attempt to bring this sort of functionality back to life was made by Saveen Reddy,

You can also try you luck with "org chart" wizard, but it's a tough guy, and it's really hard to teach the old dog new tricks.

There is one more addin out there. To be honest, I couldn't make it work, but maybe you could:


I found and corrected this code to connect shapes from excel data file. I hope it will be useful for others.

Public Sub DrawSystem()

    Dim strConnection As String
    Dim strCommand As String
    Dim strOfficePath As String
    Dim vsoDataRecordset As Visio.DataRecordset
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
                       & "User ID=Admin;" _
                       & "Data Source=" + "C:\example.xls;" _
                       & "Mode=Read;" _
                       & "Extended Properties=""HDR=YES;IMEX=1;MaxScanRows=0;Excel 12.0;"";" _
                       & "Jet OLEDB:Engine Type=34;"
    strCommand = "SELECT * FROM [Sheet1$]"
    Set vsoDataRecordset = ActiveDocument.DataRecordsets.Add(strConnection, strCommand, 0, "Objects")

Dim stnObj As Visio.Document
Dim mastObj As Visio.Master
Dim pagsObj As Visio.Pages
Dim pagObj, activePageObj As Visio.Page
Dim shpObj As Visio.Shape
Dim shpFrom As Visio.Shape
Dim shpTo As Visio.Shape

Set stnObj = Documents.OpenEx("Basic Shapes.vss", visOpenDocked)

Set pagObj = ThisDocument.Pages.Add()

Dim lngRowIDs() As Long
Dim lngRow As Long
Dim lngColumn As Long
Dim varRowData As Variant

lngRowIDs = vsoDataRecordset.GetDataRowIDs("")

Set mastObj = stnObj.Masters("Rectangle")

For lngRow = LBound(lngRowIDs) To UBound(lngRowIDs)

    varRowData = vsoDataRecordset.GetRowData(lngRow)

    If varRowData(2) = "ENTITY" Then

        Set shpObj = pagObj.Drop(mastObj, lngRow / 2, lngRow / 2)

        shpObj.Name = varRowData(3)
        shpObj.Text = varRowData(7)
        shpObj.Data1 = varRowData(3)
        shpObj.Data2 = varRowData(7)
        shpObj.Data3 = varRowData(8)

        shpObj.Cells("Width") = 0.75
        shpObj.Cells("Height") = 0.5

    End If

Next lngRow

lngRowIDs = vsoDataRecordset.GetDataRowIDs("")

Set mastObj = stnObj.Masters("Dynamic connector")

For lngRow = LBound(lngRowIDs) To UBound(lngRowIDs)

    varRowData = vsoDataRecordset.GetRowData(lngRow)
    Debug.Print ("!ddd!!" & varRowData(2))

    If varRowData(2) = "LINK" Then

        Dim fromName As String
        fromName = varRowData(4)

        Dim toName As String
        toName = varRowData(5)

        Dim conName As String
        conName = varRowData(6)

        Set shpCon = pagObj.Drop(mastObj, 2 + lngRow * 3, 0 + lngRow * 3)
        varRowData = vsoDataRecordset.GetRowData(lngRow)

        shpCon.Name = conName
        shpCon.Text = varRowData(7)

        Set shpFrom = ActivePage.Shapes(fromName)
        Set shpTo = ActivePage.Shapes(toName)
        shpFrom.AutoConnect shpTo, visAutoConnectDirNone, shpCon
    End If

Next lngRow
End Sub

to test script use this excel example

1,,ENTITY,A,,,1,1: A,ONE
2,,ENTITY,B,,,2,2: B,TWO
3,,ENTITY,C,,,3,3: C,THREE
13,1,LINK,LINK1,A,B,13.1,13.1: LINK1,LINK1
13,2,LINK,LINK2,A,C,13.2,13.2: LINK2,LINK2
13,2,LINK,LINK2,C,B,13.2,13.2: LINK2,LINK2

Tom Barton

I am fairly new to both Visio and VBA, so I hope this question is not too basic... I have been looking for an automated routine to help manage a number of network diagrams, and this would appear to fulfill the need.

I have been trying to run the code presented, but am totally unable to get it to read the Test Data. Of course, I have changed the link to the data for my environment, etc. but simply get a message that it cannot open the data file. Is there something I am missing?

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 254 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1139KB.
Tokens: post-login.
Cache hits: 14: 0.00124s for 26,767 bytes (show)
Cache misses: 3: (show)
Queries used: 15.

[Show Queries]