Pour continuer dans la lignée de la jauge, voici l'horloge analogique.

Lancez la macro Creation après avoir paramétré la position et la taille.
Cliquez sur l'horloge pour arrêter ou animer les mouvements d'aiguilles.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
'---------------------------------------------------------------------------------------
' Module      : modHorloge
' Auteur      : fred65200 - Frédéric CHAPIN
' Date        : 22/02/2009
' Description : Création d'une horloge analogique
'---------------------------------------------------------------------------------------
'
'Constantes à adapter
Const X As Integer = 100                'position horizontale
Const Y As Integer = 150                'position verticale
Const Diametre As Integer = 150         'diamètre de l'horloge
 
Const LH As Single = Diametre / 100 * 4 'largeur aiguille des heures
Const LM As Single = LH * 2 / 3         'largeur aiguille des minutes
Const LS As Single = LH / 3             'largeur aiguille des secondes
Const AxeX As Single = X + Diametre / 2 'axe vertical
Const AxeY As Single = Y + Diametre / 2 'axe horizontal
Const HH As Single = Diametre * 5 / 16  'longueur aiguille des heures
Const HM As Single = Diametre * 3 / 8   'longueur aiguille des minutes
Const HS As Single = Diametre * 7 / 16  'longueur aiguille des secondes
Const C As Single = Diametre / 8        'largeur du contour
 
Dim LHeure As Date
Dim Shp As Shape
Dim XLVersion As String
 
 
Sub Creation()
XLVersion = Val(Application.Version)
    SupprimerShapes 'Supression des shapes,sanslesboutons
    Fond            'Affichage du fond
    Batonnets       'Affichage des marqueurs de minutes
    Dessus          'Cache des bâtonnets
    Textes          'Affichage des textes
    Contour         'Affichage du contour
    Regroupement    'Regroupement des formes et application de la macro arrêt / stop
    Aiguilles       'Mise en place des aiguilles
    EnRoute         'Les aiguilles tournent
End Sub
 
Sub Aiguilles()
 
'Aiguille des heures
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LH / 2, AxeY - HH, LH, HH)
    .Name = "H1"
    .Line.Visible = msoFalse
    .Fill.Visible = msoTrue
    .Fill.ForeColor.SchemeColor = 22
    .Fill.BackColor.SchemeColor = 55
    .Fill.TwoColorGradient msoGradientVertical, 2
End With
 
If XLVersion >= 12 Then CaBrille "H1", 0, 255, 0, 0, 255, 0
 
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LH / 2, AxeY, LH, HH)
    .Name = "H2"
    .Line.Visible = msoFalse
    .Fill.Visible = msoFalse
End With
'Groupement
With ActiveSheet.Shapes.Range(Array("H1", "H2"))
    .Group
    .Name = "H"
End With
 
'Aiguille des minutes
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LM / 2, AxeY - HM, LM, HM)
    .Name = "M1"
    .Line.Visible = msoFalse
    .Fill.Visible = msoTrue
    .Fill.ForeColor.SchemeColor = 22
    .Fill.BackColor.SchemeColor = 55
    .Fill.TwoColorGradient msoGradientVertical, 2
End With
 
If XLVersion >= 12 Then CaBrille "M1", 0, 0, 255, 0, 0, 255
 
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LM / 2, AxeY, LM, HM)
    .Name = "M2"
    .Line.Visible = msoFalse
    .Fill.Visible = msoFalse
End With
'Groupement
With ActiveSheet.Shapes.Range(Array("M1", "M2"))
    .Group
    .Name = "M"
End With
 
'Aiguille des secondes
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LS / 2, AxeY - HS, LS, HS)
    .Name = "S1"
    .Line.Visible = msoFalse
    .Fill.Visible = msoTrue
    .Fill.ForeColor.SchemeColor = 22
    .Fill.BackColor.SchemeColor = 55
    .Fill.TwoColorGradient msoGradientVertical, 2
End With
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LS / 2, AxeY, LS, HS)
    .Name = "S2"
    .Line.Visible = msoFalse
    .Fill.Visible = msoFalse
End With
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LS / 2, AxeY, LS, HS / 3)
    .Name = "S3"
    .Line.Visible = msoFalse
    .Fill.Visible = msoTrue
    .Fill.ForeColor.SchemeColor = 22
    .Fill.BackColor.SchemeColor = 55
    .Fill.TwoColorGradient msoGradientVertical, 2
End With
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, AxeX - LM / 2, AxeY, LM, HS / 3)
    .Name = "S4"
    .Line.Visible = msoFalse
    .Fill.Visible = msoTrue
    .Fill.ForeColor.SchemeColor = 22
    .Fill.BackColor.SchemeColor = 55
    .Fill.TwoColorGradient msoGradientVertical, 2
End With
 
If XLVersion >= 12 Then CaBrille "S1", 255, 0, 0, 255, 0, 0: _
    CaBrille "S3", 255, 0, 0, 255, 0, 0: _
    CaBrille "S4", 255, 0, 0, 255, 0, 0
 
'Groupement
With ActiveSheet.Shapes.Range(Array("S1", "S2", "S3", "S4"))
    .Group
    .Name = "S"
End With
 
'Rond central
With ActiveSheet.Shapes.AddShape(msoShapeOval, AxeX - LH, AxeY - LH, 2 * LH, 2 * LH)
    .Name = "Centre"
    .Line.Visible = msoFalse
    .Fill.Visible = msoTrue
    .Fill.ForeColor.SchemeColor = 22
    .Fill.BackColor.SchemeColor = 55
    .Fill.TwoColorGradient msoGradientVertical, 2
End With
 
End Sub
 
Sub Regroupement()
With ActiveSheet.Shapes.Range(Array("Fond", "mesLignes", "Dessus", _
    "Trois", "Six", "Neuf", "Douze", "fred65200", "Contour"))
    .Group
    .Name = "Horloge"
End With
With ActiveSheet.Shapes("Horloge")
    .OnAction = "QueFaire"
    .AlternativeText = "Cliquez pour arrêter"
End With
End Sub
Function CaBrille(Nom As String, R1 As Byte, V1 As Byte, B1 As Byte, _
    R2 As Byte, V2 As Byte, B2 As Byte)
'    If XLVersion >= 12 Then
With ActiveSheet.Shapes(Nom)
        .Glow.Color.SchemeColor = 8
        .Glow.Radius = 5 'Max is 20
        .Glow.Color.RGB = RGB(R1, V1, B1)
        .Glow.Color.TintAndShade = 0.5
        .Shadow.Style = msoShadowStyleInnerShadow
        .Shadow.Visible = True
        .Shadow.Blur = 21
        .Shadow.ForeColor.RGB = RGB(R2, V2, B2)
        .Shadow.Transparency = 0.45
End With
'    End If
End Function
Sub Contour()
With ActiveSheet.Shapes.AddShape( _
    msoShapeDonut, _
    X - C, _
    Y - C, _
    Diametre + 2 * C, _
    Diametre + 2 * C)
    .Name = "Contour"
    .Adjustments.Item(1) = C / (Diametre + 2 * C)
    .Line.Visible = msoFalse
    .Fill.Visible = msoTrue
    .Fill.ForeColor.SchemeColor = 22
    .Fill.OneColorGradient msoGradientHorizontal, 4, 0.23
End With
End Sub
 
Sub Textes()
Dim TempL As Single
Dim TempT As Single
Dim TempW As Single
Dim TempH As Single
 TempL = ActiveSheet.Shapes("Fond").Left
 TempT = ActiveSheet.Shapes("Fond").Top
 TempW = ActiveSheet.Shapes("Fond").Width
 TempH = ActiveSheet.Shapes("Fond").Height
 
'Douze
CreerTexte TempL + TempW / 2, TempT, Diametre, 18, "Douze", "12"
'Ajustement
With ActiveSheet.Shapes("Douze")
 .IncrementLeft -.Width / 2
End With
 
'Trois
CreerTexte TempL + TempW, TempT + TempH / 2, 30, 18, "Trois", "3", xlRight
'Ajustement
With ActiveSheet.Shapes("Trois")
    .IncrementLeft -.Width
    .IncrementTop -.Height / 2
End With
 
'Six
CreerTexte TempL + TempW / 2, TempT + TempH, 30, 18, "Six", "6"
'Ajustement
With ActiveSheet.Shapes("Six")
    .IncrementLeft -.Width / 2
    .IncrementTop -.Height
End With
 
'Neuf
CreerTexte TempL, TempT + TempH / 2, 30, 18, "Neuf", "9", xlLeft
'Ajustement
With ActiveSheet.Shapes("Neuf")
    .IncrementTop -.Height / 2
End With
 
'fred65200
CreerTexte AxeX, AxeY + Diametre / 6, Diametre, 18, "fred65200", "By fred65200"
With ActiveSheet.Shapes("fred65200").TextFrame.Characters.Font
    .Name = "Brush Script Std"
    .Size = Int(Diametre / 20)
    .Color = RGB(169, 169, 169)
End With
'Ajustement
With ActiveSheet.Shapes("fred65200")
    .IncrementLeft -.Width / 2
End With
 
End Sub
 
Function CreerTexte(L As Single, T As Single, W As Single, H As Single, _
    Nom As String, Texte As String, Optional HAlign As Variant = xlCenter) As Shape
With ActiveSheet.Shapes.AddTextbox( _
    msoTextOrientationHorizontal, _
    L, _
    T, _
    W, _
    H)
    .Name = Nom
    .TextFrame.AutoSize = msoTrue
    .Line.Visible = msoFalse
    .Fill.Transparency = 1
    .TextFrame.Characters.Font.Size = IIf(Int(Diametre / 15) < 8, 8, Int(Diametre / 15))
    .TextFrame.Characters.Text = Texte
    .TextFrame.Characters.Font.Bold = True
    .TextFrame.Characters.Font.Color = RGB(0, 0, 0)
    .TextFrame.HorizontalAlignment = HAlign
    .TextFrame.VerticalAlignment = xlVAlignCenter
End With
 
End Function
 
Sub Dessus()
With ActiveSheet.Shapes.AddShape(msoShapeOval, X + 10, Y + 10, Diametre - 20, Diametre - 20)
    .Fill.ForeColor.RGB = RGB(Red:=248, Green:=248, Blue:=248)
    .Name = "Dessus"
    .Line.Visible = msoFalse
End With
End Sub
 
Sub Batonnets()
'
Dim tabLigne(1 To 30) As Variant
For i = 1 To 30                    'xDéb  , yDéb , xFin  , yFin
    With ActiveSheet.Shapes.AddLine(AxeX, Y + 5, AxeX, Y + Diametre - 5)
        .Name = "maLigne" & i
        If i Mod 5 = 0 Then
            .Line.Weight = 1.25
            .Line.ForeColor.RGB = RGB(0, 0, 0)
        Else
            .Line.Weight = 0.25
            .Line.ForeColor.RGB = RGB(169, 169, 169)
        End If
 
        If i Mod 15 = 0 Then .Line.Visible = False Else .Line.Visible = True
        .Rotation = 6 * i '30 * i
        tabLigne(i) = .Name
    End With
 
Next i
With ActiveSheet.Shapes.Range(tabLigne)
    .Group
    .Name = "mesLignes"
End With
End Sub
 
Sub Fond()
 
With ActiveSheet.Shapes.AddShape(msoShapeOval, X, Y, Diametre, Diametre)
    .Name = "Fond"
    .Fill.ForeColor.RGB = RGB(Red:=248, Green:=248, Blue:=248)
    .Line.Weight = 2
    .Line.Visible = msoFalse
    .Line.BackColor.RGB = RGB(Red:=255, Green:=255, Blue:=255)
End With
End Sub
 
Sub SupprimerShapes()
On Error GoTo Fin
For Each Shp In ActiveSheet.Shapes
     If Shp.Type <> 8 And Shp.Type <> 12 Then
       ActiveSheet.Shapes(Shp.Name).Delete
     End If
   Next Shp
Fin:
 
End Sub
'--------------------------------------------------------------------------
'
'       PARTIE MOUVEMENTS D'HORLOGE
'
'--------------------------------------------------------------------------
 
Private Sub QuelleHeure()
    ActiveSheet.Shapes("H").Rotation = (Hour(Time) + Minute(Time) / 60 + Second(Time) / 60 / 60) * 360 / 12
    ActiveSheet.Shapes("M").Rotation = Minute(Time) * 360 / 60
    ActiveSheet.Shapes("S").Rotation = Second(Time) * 360 / 60
End Sub
 
Public Sub EnRoute()
    LHeure = Now + TimeValue("00:00:01")
    Application.OnTime LHeure, "EnRoute"
    QuelleHeure
End Sub
 
Public Sub EnPause()
    On Error Resume Next
    Application.OnTime LHeure, "EnRoute", , False
    LHeure = 0
End Sub
 
Public Sub QueFaire()
Static Temoin As Boolean
    If Not Temoin Then EnRoute: Temoin = True Else EnPause: Temoin = False
End Sub
fred65200