Export the shape information in the Visio Document to the VBA code of the XML file

Source: Internet
Author: User

From the foreigners to find, made some changes, the original address: http://www.vbaexpress.com/kb/getarticle.php? Kb_id = 506

 

Option Explicit

Public Sub Locationtable ()
' This routine will create a text file of the location and size of all 2-D shapes
' On the current page
Dim Shpobj As Visio. Shape, celobj As Visio. Cell
Dim Shpno As Integer , Tabchr As String , Localcent As Double
Dim Locationx As String , Locationy As String
Dim Shapewidth As String , Shapeheight As String
Dim Unit As String

Unit = " Mm "
' Open or create text file to write data
Open " C: \ temp \ locationtable. xml " For Output shared As # 1

Tabchr = CHR ( 9 ) ' Tab

Print # 1 , " <? XML version = "" 1.0 "" encoding = "" gb2312 ""?> "
Print # 1 , " <Document Path = "" " ; Visio. activedocument. path; " "" Name = "" " ; Visio. activedocument. Name; " ""> "
Print # 1 , " <Shapes unit = "" " ; Unit; " ""> "


' Loop shapes collection
For Shpno = 1 To Visio. activepage. shapes. Count

Set Shpobj = Visio. activepage. shapes (shpno)
If Not Shpobj. ONED Then ' Only list the 2-D shapes

' Get location shape
Set Celobj = shpobj. cells ( " Pinx " )
Localcent = celobj. Result (unit)
Locationx = localcent ' Format (localcent, "000.0000 ")
Set Celobj = shpobj. cells ( " Piny " )
Localcent = celobj. Result (unit)
Locationy = format (localcent, " 000.0000 " )

' Get size shape
Set Celobj = shpobj. cells ( " Width " )
Localcent = celobj. Result (unit)
Shapewidth = format (localcent, " 000.0000 " )
Set Celobj = shpobj. cells ( " Height " )
Localcent = celobj. Result (unit)
Shapeheight = format (localcent, " 0.0000 " )

' Write values to text file starting name of shape
Print # 1 , " <Shape name = "" " ; Shpobj. Name; " "" Type = "" " ; Shpobj. type; " "" Text = "" " ; Shpobj. text; " "" Bounds = "" " ;_
Locationx; " , " ; Locationy; " , " ; Shapewidth; " , " ; Shapeheight; " ""/> "
End If

Next Shpno

Print # 1 , " </Shapes> "
Print # 1 , " </Document> "
' Close textfile
Close # 1

' Clean up
Set Celobj = Nothing
Set Shpobj = Nothing
End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.