-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafy
127 lines (114 loc) · 4.64 KB
/
grafy
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
Attribute VB_Name = "grafy"
Sub graf()
'
'Function for creating graphs.
'
' On Error GoTo ErrorCounter
On Error Resume Next 'if error occures, usualy helps to run function second time
Dim Pic As Object
Range(GRAPH_RANGE).Select 'double check of deleting space where graphs will be
Range(GRAPH_RANGE).Delete
Range(GRAPH_RANGE).Clear
For Each Pic In ActiveSheet.Pictures
If Not Intersect(Pic.TopLeftCell, Range(GRAPH_RANGE_PLUS_ONE)) Is Nothing Then
Pic.Delete
End If
Next Pic
'find every picture in given range and delete it. Excel is not deleting pictures
'with Delete or Clear functions
'
' /// Graph of height ///
'
Range("AL16:AR25").Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select 'create graph of type 2
ActiveChart.SetSourceData Source:=Range("AI17:AJ25") 'source data
With ActiveChart.Parent
.Top = Range("AL16").Top 'set position of graph - upper border on this cell
.Left = Range("AL16").Left 'left border at this cell
.Width = Range("AL16:AR25").Width
.Height = Range("AL16:AR25").Height
End With
ActiveChart.HasLegend = False
With ActiveChart.Axes(xlCategory) 'add label to the lower axis
.HasTitle = True
.AxisTitle.Text = "Výška knihy v cm"
End With
With ActiveChart.Axes(xlValue) 'add label of left axis
.HasTitle = True
.AxisTitle.Text = "Poèet kníh"
End With
ActiveChart.Parent.Name = "Graf1" 'add graph a name so I can manipulate it
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "Výška kníh"
ActiveChart.FullSeriesCollection(1).ApplyDataLabels 'activate graph's labels
ActiveChart.ChartGroups(1).GapWidth = 52
Application.CommandBars("Format Object").Visible = False
ActiveChart.PlotArea.Select
Application.CommandBars("Format Object").Visible = False
ActiveChart.ChartArea.Select
ActiveChart.FullSeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(79, 129, 93)
.Transparency = 0
.Solid
End With
ActiveSheet.ChartObjects("Graf1").Activate 'activate the specific graph
ActiveChart.Parent.Cut 'cut it to clipboard
Range("AT16").Select 'and paste it to different cell
ActiveSheet.Paste
'there was a problem with exporting graph as a picture, when it was only in clipboard
ActiveSheet.ChartObjects("Graf1").Chart.CopyPicture xlScreen, xlBitmap 'select graph, copy it as a picture
ActiveSheet.ChartObjects("Graf1").Delete 'delete graph
Range("AL16").Select
ActiveSheet.Pictures.Paste.Select 'paste pic of graph
'
' /// Graph of width ///
'
' same Algortihm as above, but for different graph.
'Maybe it could be written more general way and applied for both graphs at once,
'but I doubt it would improve performance
Range("AL27:AR36").Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("AI28:AJ36")
With ActiveChart.Parent
.Top = Range("AL27").Top
.Left = Range("AL27").Left
.Width = Range("AL27:AR36").Width
.Height = Range("AL27:AR36").Height
End With
ActiveChart.HasLegend = False
With ActiveChart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "Šírka knihy v cm"
End With
With ActiveChart.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = "Poèet kníh"
End With
ActiveChart.Parent.Name = "Graf2"
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "Šírka kníh"
ActiveChart.FullSeriesCollection(1).ApplyDataLabels
ActiveChart.ChartGroups(1).GapWidth = 52
ActiveChart.ChartColor = RGB(79, 129, 93)
Application.CommandBars("Format Object").Visible = False
ActiveChart.PlotArea.Select
Application.CommandBars("Format Object").Visible = False
ActiveChart.ChartArea.Select
ActiveChart.FullSeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(79, 129, 93)
.Transparency = 0
.Solid
End With
ActiveSheet.ChartObjects("Graf2").Activate
ActiveChart.Parent.Cut
Range("AT27").Select
ActiveSheet.Paste
ActiveSheet.ChartObjects("Graf2").Chart.CopyPicture xlScreen, xlBitmap
ActiveSheet.ChartObjects("Graf2").Delete
Range("AL27").Select
ActiveSheet.Pictures.Paste.Select
End Sub