Solved

Import data into visio file from XML

Posted on 2012-04-12
4
1,059 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
visio template 2 632
Visio 2010 - 4 384
Is there a way to hide default shape's right click pop up menu (context menu) in Visio 2013? 3 254
Process mapping 5 67
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 …
The Question Several times in recent years, someone has posted a question at EE asking whether they could display the Windows directory structure – folders and subfolders – using Visio. When one person specifically asked about displaying directory …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

732 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