-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_vsd_DocsShapesLinks.bas
122 lines (90 loc) · 2.84 KB
/
mod_vsd_DocsShapesLinks.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Attribute VB_Name = "mod_vsd_DocsShapesLinks"
' mod_vsd_DocsShapesLinks
' 150413.AMG begin doc and hyperlink update code
' 150313.AMG added Doc stuff renamed from mod_vsd_ShapesLinks
' 150303.AMG created
'
' Visio Object Model Overview https://msdn.microsoft.com/en-us/library/cc160740.aspx
' Visio Object Model Reference https://msdn.microsoft.com/en-us/library/office/ff765377(v=office.15).aspx
'
'
' Visio Shapes ***********************
'
' Shapes collections are sub-objects of Page, Master or Shape
' Shapes contained by other Shapes are caused by Grouping (a common occurance) and are known as sub-shapes
'
' Shapes Object https://msdn.microsoft.com/en-us/library/office/ff767583.aspx
'
'
' Visio Hyperlinks ***********************
'
' Hyperlinks collections are sub-objects of Shape
'
' Hyperlinks object https://msdn.microsoft.com/en-us/library/office/ff766930.aspx
' Hyperlink object https://msdn.microsoft.com/en-us/library/office/ff767835.aspx
'
Option Explicit
Function EnumHyperlinks(shp As Shape)
Dim hlk As Hyperlink
If shp.Hyperlinks.Count > 0 Then
For Each hlk In shp.Hyperlinks
' DoSomethingWith hlk
' AddHyperlinkDetailToList hlk
UpdateHyperlinkDetail hlk
Next
End If
End Function
Function UpdateHyperlinkDetail(hlk As Hyperlink)
Dim strNewAddress As String
' ignore empty hyperlinks
If hlk.Description & hlk.Address <> "" Then
strNewAddress = ""
AddHyperlinkDetailToList hlk, strNewAddress
' ExcelOutputWriteValue strCurrentFileFolder
' ExcelOutputWriteValue strCurrentFileNameOnly
' ExcelOutputWriteValue hlk.Shape.Name
' ExcelOutputWriteValue hlk.Shape.Text
' ExcelOutputWriteValue hlk.Description
' ExcelOutputWriteValue hlk.Address
' ExcelOutputWriteValue strNewAddress
' ExcelOutputNextRow
If Not bTrialRun Then
hlk.Address = strNewAddress
End If
End If
End Function
' Docs
' Docs and Shapes
Function VisioOpenAndRecurseAllShapesInDoc( _
strFileName As String _
, Optional bSave As Boolean = False _
)
Dim doc As Document
Set doc = Application.Documents.Open(strFileName)
RecurseAllShapesInDoc doc
If bSave Then
doc.Save
End If
doc.Close
Set doc = Nothing
End Function
Function RecurseAllShapesInDoc(doc As Document)
Dim pg As Page
Dim shp As Shape
For Each pg In ActiveDocument.Pages
For Each shp In pg.Shapes
DoEachShapeAndSubShape shp
Next
Next
End Function
Function DoEachShapeAndSubShape(shp As Shape)
Dim subshp As Shape
' do the main shape
EnumHyperlinks shp
' if there are subshapes then recurse into them
If shp.Shapes.Count() <> 0 Then
For Each subshp In shp.Shapes
DoEachShapeAndSubShape subshp
Next
End If
End Function