我想在Visio 2007中通过VBA将某些图层导出到svg。
我无法在选择中添加图层。我该怎么做?
Sub tester()
Dim Layer As Visio.Layer
Dim Layers As Visio.Layers
Dim sel As Visio.Selection
Dim filename As String
Dim lyrName As String
Dim iLays As Integer
Set Layers = Application.ActivePage.Layers
Set sel = EmptySelection 'Or whatever empty initialization neeeds to happen...
For iLays = 1 To Layers.Count
Set Layer = Layers(iLays)
lyrName = Layer.Name
If lyrName = "Walls" Or lyrName = "Zones" Then
sel.AddLayer (lyrName) 'or some such nonsense - This is broked.
End If
filename = Application.ActiveDocument.Path & "PootyStuff.svg"
'Export the page as svg file
sel.Export filename
Next iLays
Set Layer = Nothing
Set Layers = Nothing
End Sub
答案 0 :(得分:1)
试试此代码
Sub tester()
Dim sel As Visio.Selection
Dim filename As String
ActiveWindow.DeselectAll
' create selection by layers
Set sel = ActivePage.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, "Walls;Zones")
filename = Application.ActiveDocument.Path & "PootyStuff.svg"
'Export the page as svg file
sel.Export filename
End Sub