-
Notifications
You must be signed in to change notification settings - Fork 11
/
Excel VBA - Adding Shape.vb
100 lines (78 loc) · 2.32 KB
/
Excel VBA - Adding Shape.vb
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
Option Explicit
Dim this_Sheet As Worksheet
'
' This adds a new rectangular shape to an Excel sheet
'
Sub add_NewBox()
'Set sheet
Set this_Sheet = Worksheets(ActiveSheet.Index)
'Add new shape
this_Sheet.Shapes.AddShape(msoShapeRectangle, 150, 150, 320, 30).Visible = msoTrue
'Get the last shape
Dim last_Shape As Long
last_Shape = count_Shapes
'Style shape
With this_Sheet.Shapes.Item(last_Shape)
.BackgroundStyle = msoBackgroundStylePreset2
.Line.Visible = msoFalse
With .TextFrame2
.TextRange.Text = "Google"
With .TextRange.Font
.Fill.ForeColor.RGB = RGB(1, 1, 1)
.Size = 12
.Name = "Open Sans"
End With
.TextRange.ParagraphFormat.Alignment = msoAlignCenter
End With
End With
End Sub
Private Function count_Shapes() As Long
'
' This function counts the amount of shapes
'
count_Shapes = this_Sheet.Shapes.Count
End Function
'
' Same with shape shadow
'
Option Explicit
Dim this_Sheet As Worksheet
Sub add_NewBox()
'Set sheet
Set this_Sheet = Worksheets(ActiveSheet.Index)
'Add new shape
this_Sheet.Shapes.AddShape(msoShapeRectangle, 150, 150, 320, 30).Visible = msoTrue
'Get the last shape
Dim last_Shape As Long
last_Shape = count_Shapes
'Style shape
With this_Sheet.Shapes.Item(last_Shape)
.BackgroundStyle = msoBackgroundStylePreset2
.Line.Visible = msoFalse
With .Shadow
.Blur = 5
.Transparency = 0.7
.OffsetX = -1
.OffsetY = 1
.Visible = msoTrue
End With
With .TextFrame2
With .TextRange
.ParagraphFormat.Alignment = msoAlignCenter
With .Font
.Fill.ForeColor.RGB = RGB(1, 1, 1)
.Size = 12
.Name = "Open Sans"
End With
.Text = "-- Tapez votre texte ici --"
.Select
End With
End With
End With
End Sub
Private Function count_Shapes() As Long
'
' This function counts the amount of shapes
'
count_Shapes = this_Sheet.Shapes.Count
End Function