Excel to Visio VBA

scm160

Board Regular
Joined
Mar 4, 2016
Messages
97
Hi Guys,

Trying to create an org chart for my company. Based off an excel spreadsheet of named resources.


After creating an array of resources with Name / Role / Employer / Location - I'm trying to setup a loop/select case that will create a Visio Document (landscape orientation) and will create the shapes / team title the resource is working for.

So far I've been having trouble creating shapes within my loop. Not sure why but the code provided by MSDN doesn't seem to work Shape.DrawRectangle method does not work and results in Error 429. Macro recorder does not work either getting from the Shapes window.

Ideally want I want to do is to write the titles of each Team then offset rectangle shapes below listing out the resources (while looping through the array). When that team is complete then write the next header for a different team and so on. It doesn't matter where the resources goes because the whole point is to automate the creation of these Visio rectangles with the resources' details. The user will have to manually organize them on the page in order fit everything on the page correctly.

Can anyone help me with this ???

Heres a cut of my code so far (2 hours in w/ Visio stuff).....

Code:
'loop Calls the Visio Procedure

Sub OpenVisioDoc()
     Dim VisioApp As Visio.Application
     Dim VisDoc As Visio.Document
     Dim VisShape As Visio.Shape

        Set VisioApp = CreateObject("Visio.Application")
    VisioApp.Documents.AddEx "", visMSDefault
    VisioApp.ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageWidth).FormulaU = "11 in"
    VisioApp.ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).FormulaU = "8.5 in"
    
    VisioApp.Windows.ItemEx("Drawing3").Activate
    VisioApp.ActiveWindow.Page.Drop VisioApp.Documents.Item("Stencil4").MasterShortcuts.ItemU("Rectangle"), 2.256152, 7.659449

    Dim UndoScopeID1 As Long
    UndoScopeID1 = VisioApp.BeginUndoScope("Size & Position 2-D")
    VisioApp.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = "1 in"
    VisioApp.EndUndoScope UndoScopeID1, True

    Dim UndoScopeID2 As Long
    UndoScopeID2 = VisioApp.BeginUndoScope("Size & Position 2-D")
    VisioApp.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = "0.5 in"
    VisioApp.EndUndoScope UndoScopeID2, True

    Dim vsoCharacters3 As Visio.Characters
    Set vsoCharacters3 = VisioApp.ActiveWindow.Page.Shapes.ItemFromID(1).Characters
    vsoCharacters3.Begin = 0
    vsoCharacters3.End = 0
    vsoCharacters3.Text = "Gunnar Gunnarson" & Chr(10) & "Analyst" & Chr(10) & "Xyz Company"
    
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,217,085
Messages
6,134,473
Members
449,874
Latest member
Cl2130

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top