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
| Private Sub CommandButton1_Click()
'Variables declaration
Dim vFileName As Variant 'For the selection of the file
Dim WkbS As Workbook 'Workbook Source = DATA EXTRACTOR.xls
Dim WkbC As Workbook 'Workbook created = Excel file created
Dim WksC As Worksheet 'Worksheet in WksC with values
Dim ChartSheet As Worksheet 'Worksheet in WksC with the chart
Dim CChart As Chart 'Created Chart = the chart in Chartsheet
Dim Cell As Range 'Cell
'Data extraction from .tlv file
Set WkbS = ThisWorkbook
vFileName = Application.GetOpenFilename
If vFileName = False Then
Else
Workbooks.OpenText Filename:=vFileName, _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=True, Semicolon:=False, Comma:=False, Space:=False, Other:=False, _
DecimalSeparator:=".", ThousandsSeparator:=",", TrailingMinusNumbers:=True
Set WkbC = ActiveWorkbook
Set WksC = ActiveSheet
ActiveSheet.Name = "Data"
WkbC.Sheets(1).Columns("A:A").Select
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss"
WkbC.Sheets(1).Columns("A:E").ColumnWidth = 30
WkbC.Sheets(1).Columns("B:F").HorizontalAlignment = xlRight
WkbC.Sheets(1).Columns("A:A").HorizontalAlignment = xlCenter
WkbC.Sheets(1).Range("A1:F3").HorizontalAlignment = xlCenter
'Line chart creation
Set ChartSheet = Sheets.Add
ActiveSheet.Name = "ChartSheet"
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "='Data'!$B$1"
ActiveChart.SeriesCollection(1).XValues = "='Data'!$A$4:$A$65536"
ActiveChart.SeriesCollection(1).Values = "='Data'!$B$4:$B$65536"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "='Data'!$C$1"
ActiveChart.SeriesCollection(2).XValues = "='Data'!$A$4:$A$65536"
ActiveChart.SeriesCollection(2).Values = "='Data'!$C$4:$C$65536"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "='Data'!$D$1"
ActiveChart.SeriesCollection(3).XValues = "='Data'!$A$4:$A$65536"
ActiveChart.SeriesCollection(3).Values = "='Data'!$D$4:$D$65536"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(4).Name = "='Data'!$E$1"
ActiveChart.SeriesCollection(4).XValues = "='Data'!$A$4:$A$65536"
ActiveChart.SeriesCollection(4).Values = "='Data'!$E$4:$E$65536"
ActiveChart.ApplyLayout (8)
With ActiveChart.ChartArea.Format.Line
.Visible = msoCTrue
.DashStyle = msoLineSolid
.Weight = 3
End With
ActiveChart.HasTitle = True
With ActiveChart.ChartTitle
.Characters.Font.Size = 18
.Text = "Compressor KOS1"
End With
With ActiveChart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "Time"
End With
With ActiveChart.Axes(xlValue)
.MaximumScale = 300
End With
With ActiveChart.Parent
.Left = 25
.Top = 100
.Width = 950
.Height = 450
End With
'Buttons creation
ActiveSheet.Buttons.Add(61.5, 20, 75, 20).Select
Selection.OnAction = "TimeRange"
ActiveSheet.Shapes("Button 1").Select
Selection.Characters.Text = "Time range"
With Selection.Characters(Start:=1, Length:=7).Font
.Name = "Arial"
.FontStyle = "Standard"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
ActiveSheet.Buttons.Add(250, 20, 75, 20).Select
Selection.OnAction = "ValuesRange"
ActiveSheet.Shapes("Button 2").Select
Selection.Characters.Text = "Values range"
With Selection.Characters(Start:=1, Length:=8).Font
.Name = "Arial"
.FontStyle = "Standard"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
End With
ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=41.25, Top:=54, Width:=57, Height:=16.5). _
Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=110.25, Top:=53.25, Width:=63, Height:= _
17.25).Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=242.25, Top:=52.5, Width:=63, Height:= _
16.5).Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=317.25, Top:=52.5, Width:=71.25, Height:= _
16.5).Select
End If
End Sub |
Partager