Solved

Import data into visio file from XML

Posted on 2012-04-12
4
1,038 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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 …
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article we’ll examine containers. We’ll explore lists (http://www.experts-exchange.com/Microsoft/Applications/M…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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