Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1125
  • Last Modified:

Import data into visio file from XML

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
ShaileshShinde
Asked:
ShaileshShinde
  • 2
  • 2
2 Solutions
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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
 
ShaileshShindeAuthor Commented:
Thanks Expert! Will look at this info and get back to you.

Thanks,
Shail
0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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
 
ShaileshShindeAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now