-
Notifications
You must be signed in to change notification settings - Fork 1
/
modCreateLayers.bas
118 lines (74 loc) · 2.33 KB
/
modCreateLayers.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
Attribute VB_Name = "modCreateLayers"
Option Explicit
Public Sub ColorToLayer()
ActiveDocument.BeginCommandGroup "ColorToLayer"
Dim i As Integer
Dim s As Shape
Dim sr As ShapeRange
Dim p As page
Dim l As Layer
Dim aux As String
Dim cfg As New clsSettings
Dim exists As Boolean
cfg.TurnOff
Set p = ActiveDocument.ActivePage
i = 0
p.Layers(2).Activate
For Each s In p.Shapes
i = i + 1
s.CreateSelection
Set sr = ActiveSelectionRange
On Error Resume Next
If s.Fill.Type <> cdrNoFill Then
aux = s.Fill.UniformColor.RGBValue
For Each l In p.Layers
If l.Name = aux Then
exists = True
Set l = l
Exit For
End If
Next l
If exists Then
sr.Item(1).MoveToLayer l
Else
Set l = p.CreateLayer(aux)
sr.Item(1).MoveToLayer l
End If
End If
exists = False
Next s
Call DeleteLayers(p)
cfg.TurnOn
ActiveDocument.EndCommandGroup
MsgBox "Finished", vbInformation, "ColorToLayer"
Set s = Nothing
Set sr = Nothing
Set l = Nothing
Set p = Nothing
End Sub
Public Sub DeleteLayers(ByRef page As page)
ActiveDocument.BeginCommandGroup "DeleteLayers"
Dim l As Layer
For Each l In ActivePage.Layers
If l.Shapes.Count = 0 And l.Index > 1 Then l.Delete
Next l
Set l = Nothing
ActiveDocument.EndCommandGroup
End Sub
Private Sub ActivatePage()
ActiveDocument.BeginCommandGroup "ActivatePage"
Dim p As page
Dim cfg As New clsSettings
cfg.TurnOff
For Each p In ActiveDocument.Pages
Call DeleteLayers(p)
Next p
cfg.TurnOn
Set p = Nothing
ActiveDocument.EndCommandGroup
End Sub
Public Sub ActivateSettings()
Dim cfg As New clsSettings
cfg.TurnOff
cfg.TurnOn
End Sub