我的宏将所有页中所有Visio形状中的所有文本导出到每个Visio页的Excel工作表中。再次感谢Paul Herber,他将错误识别为ShapesList ActivePage.Shapes
,应该是ShapesList vsPage.Shapes
,下面的代码现在可以正常工作了。
Sub ExportVisioTextsExcel()
Dim vsPage As Visio.Page
Dim vsDoc As Visio.Document
Dim xlApp, xlWB, xlWS, vsApp As Object
Dim FldPath As String
Set xlApp = CreateObject("Excel.Application")
Set vsApp = CreateObject("Visio.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Add
Set vsDoc = vsApp.Documents.Open("C:\xyz\File.vsdx")
FldPath = "C:\xyz\"
For Each vsPage In vsDoc.Pages
Set xlWS = xlWB.Sheets.Add(After:=xlWB.Worksheets(xlWB.Worksheets.Count))
ShapesList vsPage.Shapes, xlWS
Next vsPage
xlWB.SaveAs FldPath & "xxx" & Format(Now(), "YYYYMMDD")
MsgBox "Texts exported", vbInformation
End Sub
Sub ShapesList(ByVal shps As Shapes, ByVal xlWS As Object)
Dim sh As Shape
Dim vChars As Visio.Characters
Dim lRow As Long
lRow = xlWS.Cells(xlWS.Rows.Count, 1).End(xlUp).Row
For Each sh In shps
If sh.Shapes.Count = 0 Then
If Not sh.OneD Then
Set vChars = sh.Characters
xlWS.Cells(lRow, 1).Value = sh.ID
xlWS.Cells(lRow, 2).Value = sh.Name
xlWS.Cells(lRow, 3).Value = vChars.Text
lRow = lRow + 1
End If
End If
ShapesList sh.Shapes, xlWS
Next sh
End Sub
感谢http://visguy.com/vgforum/index.php?PHPSESSID=76f6964e4d1518f3495af46e92c2a609&topic=10128.0上的@PaulHerber、@Surrogate和@wapperdude
1条答案
按热度按时间2jcobegt1#
CreateSelection将不标识和选择组子形状。它需要递归算法来逐步进入一个组和其中的任何后续组。
通过发布的代码,
1.“选择所有线”捕获每个顶层形状并且仅捕获顶层形状。
1.下一行将这些形状分组
1.取消分组行取消对所有顶层形状的分组。如果在任何顶级对象中存在其他组,则不会取消对这些组的编组。
不建议执行取消分组过程,因为智能形状可能会被破坏。此外,与主形状的链接也将断开。
一个工作解决方案与Visio测试文件张贴在这里:该http://visguy.com/vgforum/index.php?topic=10128.msg46806#msg46806解决方案不使用解分组并且是非破坏性的。