Create Visio document from Excel using VBA

bydganwil

New Member
Joined
Jul 20, 2012
Messages
27
Hi there,

I have a spreadsheet with 20 rows of data with just 1 column. I need to create a visio document for each row and display the data within it. I am not concerned about how the data is displayed within Visio.

I hope somebody can help.

Rob
 
It would be really helpful, if anybody who is a part of this forum can help me through my request.

Thanks again!!
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi Sayre,

Thank you very much for the effort. When I try to run the code, I get a 'compile error: user-defined type not defined'. What can I do about this? Can you help me out with this?
 
Upvote 0
Sebhoo, did you add a reference to the visio application in your VBE?

Phil actually put some instructions for this in earlier versions of his script:

'If the error "User-defined type not defined' is displayed you must add a
'Reference to the Visio Application to the VBA Environment as follows:
'1) From the Microsoft Visual Basic window menu: Tools | References
'2) Scroll to and select 'Microsoft Visio x.x Type Reference Library
'3) Click OK.
'4) From the Microsoft Visual Basic window menu: File | Close and Return to Microsoft Excel
'Start code with the worksheet containing the array as the Active Worksheet
 
Upvote 0
I appreciate all the help from this forum and thread.

I have 250 people in my organization and I'm trying to create a Visio chart that reflects the correct hierarchy, but using different shapes that aren't natural to Visio. I've created a custom stencil and have been playing with earlier versions of scripts from this forum but I'm running into a strange issue.

Here's my data:

Name Reports To Title
David EVP
Bob David SVP
Karen David SVP
Doug Karen SD
Beth Karen Manager


I'd like connecters between the top person down to the next person, but also use the custom shape. The import wizard will do it but not use the correct shapes for our company, and doesn't like the number of people we have.

I've been playing with this code which just looks at their basis name (not the other two columns), but when I use natural shapes, e.g., diamonds, triangles, etc. it works perfectly; yet when I use my custom shapes the names all get added to 1 or 2 shapes and the remaining ones are blank.

Code:
Sub VisioFromExcel()

    Dim AppVisio As Object
    Dim vsoCharacters1 As Visio.Characters
    Dim lX As Long
    Dim dXPos As Double
    Dim dYPos As Double
    Dim xs As Double
    Dim ys As Double
    
    
    'Const visSectionCharacter = 3
    'Const visCharacterSize = 7
    
    Set AppVisio = CreateObject("visio.application")
    AppVisio.Visible = True
    
    AppVisio.Documents.AddEx "", visMSDefault, 0 'Open Blank Visio Document
    AppVisio.Documents.OpenEx "Custom1.vssx", visOpenRO + visOpenDocked   'Add Basic Stencil
    
    dXPos = AppVisio.ActivePage.PageSheet.Cells("PageWidth") / 2
    dYPos = AppVisio.ActivePage.PageSheet.Cells("PageHeight") / 2


    xs = 0


    For lX = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    
        
       AppVisio.Windows.ItemEx(1).Activate
       AppVisio.ActiveWindow.Page.Drop AppVisio.Documents.Item("Customs1.vssx").Masters.ItemU("SVP"), dXPos +xs, dYPos
    
        Set vsoCharacters1 = AppVisio.ActiveWindow.Page.Shapes.ItemFromID(lX).Characters
        vsoCharacters1.Begin = 0
        vsoCharacters1.End = 0
        vsoCharacters1.Text = CStr(Cells(lX, 1).Value)
        Debug.Print vsoCharacters1.Text
        
        AppVisio.ActiveWindow.Page.Shapes.ItemFromID(lX).CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU = "24 pt"
        
        xs = xs + 1
    
    Next
    
    Set AppVisio = Nothing
    
End Sub


Thoughts on why I am getting all the names in 1 or 2 of the custom shapes? How hard would it be to do what I'm looking to do at the top? I could also break the 250 up into separate organizations so that it limits the number of shapes/people in one organization.
 
Upvote 0
I'm trying to connect two complex stencils in Visio from Excel . What is the best way to identify the connection points ?
 
Last edited:
Upvote 0
Activate the connection point tool. It shows small X where the connection points are and you can add more if needed.
 
Upvote 0
Activate the connection point tool. It shows small X where the connection points are and you can add more if needed.

I'm trying to do this from excel VBA. I need to link complex stencils (123) and (456) in example below in sequence. I have two connection points at each edge, and need to connect as shown below. How do I identify the edge shapes or connection points within a group that comes from a stencil ?

open
 
Last edited:
Upvote 0
I don't know. Post in the forums at Visio Guy and see if they can tell you how to do it in Visio VBA, then use the earlier examples in this post to modify that code to run from Excel.
 
Upvote 0
Dear Phil,

When i read this item about create visio from excel, i am so excited. Because i always try to use work with excel first than draw visio flowcharts.

I have process steps in excel as you see in the attached file. this tell which step is process or decision; step goes to another one it is also mentioned.

I also add visio flowchat which i draw manual and i add step explanation myself.

How can i draw flawchart in visio automatically when i link the excel file? Is it possible? I use excel file always same rows and coloumns same titles.

Could you please help me, how can i draw automatically in visio from excel process below.

C:\Users\demirtas_c\Desktop\2016-09-26_232948.jpg
Process StepFlowDepartmentExplaingo to process stepgo to process step (2)
1StartFinal Inspectioninspection starts2
2ProcessFinal Inspectiondetect wider(10cm more) or narrow width3
3DecisionFinal Inspectionis it sample order or production order ?45
4ProcessFinal Inspectionif it is sample order inspect as 1st choice and cut as 2nd choice12
5ProcessFinal Inspectioninspect and cut as 1st choice, do not block the pieces6
6DataFinal Inspectioninform QA by e-mail7
7DataQuality Assuranceanalyse similar qualities and previous productions then inform Sales by e-mail8
8DecisionCustomer Serviceis it ok or not?910
9ProcessQuality Assuranceif the width is ok, note in material and inform Final Inspection for the next orders16
10ProcessQuality Assuranceask Product Development to create new material11
11ProcessProduct Developmentcreate new material16
12DataSample Roominform sales about nonconform width by e-mail13
13DecisionCustomer Serviceis it ok or not?1415
14ProcessSample Roomif the width is ok, note in material16
15ProcessCustomer Servicecreate new material to reach requested width(new sample order)16
16EndxEnd


<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,325
Messages
6,124,252
Members
449,149
Latest member
mwdbActuary

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