visio转化为txt信息

			

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 'Open or create text file to write data Open "C:\LocationTable.txt" For Output Shared As #1 Tabchr = Chr(9) 'Tab '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("inches") LocationX = Format(localCent, "000.0000") Set celObj = shpObj.Cells("piny") localCent = celObj.Result("inches") LocationY = Format(localCent, "000.0000") 'Get Size Shape Set celObj = shpObj.Cells("width") localCent = celObj.Result("inches") ShapeWidth = Format(localCent, "000.0000") Set celObj = shpObj.Cells("height") localCent = celObj.Result("inches") ShapeHeight = Format(localCent, "000.0000") 'Write values to Text file starting Name of Shape Print #1, shpObj.Name; shpObj.Text; Tabchr; _ Tabchr; LocationX; Tabchr; LocationY; _ Tabchr; ShapeWidth; Tabchr; ShapeHeight End If Next ShpNo 'Close Textfile Close #1 'Clean Up Set celObj = Nothing Set shpObj = Nothing End Sub

How to use:

  1. Open your Visio document.
  2. Press Alt + F11 to launch the Visual Basic Editor (VBE).
  3. Select Insert>Module from the Menu Bar in the VBE.
  4. Copy the code from above.
  5. Paste the code in the right hand window of the VBE.
  6. Close the VBE.
  7. From the Visio document, select Tools>Macro>Macros (or press Alt + F8).
  8. Highlight LocationTable in the list of macros.
  9. Press run.
 

Test the code:

  1. Open the example file.
  2. Run the LocationTable macro per the instructions above.
  3. Add a 2d shape to the document.
  4. Run the LocationTable macro again.
  5. Notice that the shape you added is now listed in the text document.
  6. When you are convinced that it works right, place the code in your document and run it.
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值