Solved

Import data into visio file from XML

Posted on 2012-04-12
4
1,019 Views
Last Modified: 2012-05-07
Hello Experts,

I have extracted "DisplayedText" and "ShapeID" from the visio file into XML. I would like to import back this xml file into visio with the reference of ShapeID using macro.
Is there any reference macro code for this?

Attached sample.xml file for the reference.  

Thanks in Advance.
Shail
Sample.xml
0
Comment
Question by:ShaileshShinde
  • 2
  • 2
4 Comments
 
LVL 30

Assisted Solution

by:Scott Helmers
Scott Helmers earned 500 total points
ID: 37870602
Shail -- big apology for not getting to this question yet. I will provide a bit of VBA code that should get you started.

For a different approach, please take a look at this evolving thread if you haven't already:
http://www.experts-exchange.com/Microsoft/Applications/Microsoft_Visio/Q_27661631.html
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 37874682
Thanks Expert! Will look at this info and get back to you.

Thanks,
Shail
0
 
LVL 30

Accepted Solution

by:
Scott Helmers earned 500 total points
ID: 37880769
The attached Visio diagram includes several shapes and the code shown below. The code doesn't read the XML file, but it does show you what's necessary to use the shape ID you read from XML to locate the shape on the page. I didn't include the XML-related code because the question I referenced above now includes XML code that you should be able to adapt. If you need help doing so, just ask...
Sub ReadXML_WriteToShapes()
' read shape ID and displayed text from XML and write to shapes in Visio

' IMPORTANT NOTE: Visio shape IDs are unique per page not per document. Consequently, this code
' assumes that the IDs read from the XML file apply to shapes on the current page.


    Dim doc As Visio.Document
    Dim pg As Visio.Page
    Dim shp As Visio.Shape
    
    Dim sID As String
    Dim sText As String
    
    Set doc = ActiveDocument
    Set pg = ActivePage
    

'>>> Loop through XML document here

    'For Each xmlNode In xmlDoc...

        ' values are set here just for example
        sID = "6"                               ' Get Shape ID from XML node
        sText = "Sample text for a shape"       ' Get Displayed text from XML node
    
        On Error Resume Next
        Set shp = pg.Shapes.ItemFromID(sID)
        ' allow for case that shape does not exist on this page
        If Not shp Is Nothing Then
            shp.Text = sText
        End If

    'Next

End Sub

Open in new window

Import-XML-to-Visio-shapes.vsd
0
 
LVL 1

Author Closing Comment

by:ShaileshShinde
ID: 37940037
Thanks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever created a custom Visio stencil – a collection of your own unique master shapes – and then created a drawing by dragging masters onto the drawing page? Have you then made changes to the stencil master and wondered why the shapes on the …
Meetings to discuss business process can waste time, and often do .  The meeting's dialog can get confusing when participants have different professional perspectives and backgrounds.  A jointly-developed process picture helps wade through the confu…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now