?
Solved

Import data into visio file from XML

Posted on 2012-04-12
4
Medium Priority
?
1,067 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 31

Assisted Solution

by:Scott Helmers
Scott Helmers earned 1500 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 31

Accepted Solution

by:
Scott Helmers earned 1500 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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…
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 I’ll describe a mashup of containers and lists that meet a real-world need. Prior to reading this ar…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

764 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