|
运行到Set mychart = ActiveSheet.ChartObjects.Add(.Cells(k, 9).Left, .Cells(k, 9).Top, 620, 280)
时出错,同一个文件有的电脑可以有的出错
Sub new_chart()
Dim mychart As ChartObject, j As Integer, k As Integer, i As Integer, ws As Worksheet, d As Integer, z As Integer
Dim actchart As ChartObject
Sheets("Density").Activate
d = Sheets("density").Range("C1:QN1").Find(what:=Date - 1).Column
Set ws = Sheets("MAP & Chart")
z = 0
For k = 1 To 57 Step 7 '43gia55
z = z - 1
ws.Activate
With ws
For Each mychart In ws.ChartObjects
If mychart.Name = .Cells(k, 9).Value Then mychart.Delete
Next mychart
Set mychart = ActiveSheet.ChartObjects.Add(.Cells(k, 9).Left, .Cells(k, 9).Top, 620, 280)
mychart.Name = .Cells(k, 9)
With mychart.Chart
.HasTitle = True
.ChartTitle.Text = mychart.Name & "_Defect_Density"
.ChartTitle.Font.Size = 18
.Axes(xlValue).MajorGridlines.Delete
.ChartGroups(1).GapWidth = 100
.HasLegend = True
.Legend.Font.Size = 16
.Legend.Position = xlLegendPositionRight
For i = 1 To 4
With .SeriesCollection.NewSeries
.Values = Range(Sheets("density").Cells(1 + i, d - 11), Sheets("density").Cells(1 + i, d))
.XValues = Range(Sheets("density").Cells(1, d - 11), Sheets("density").Cells(1, d))
.Name = Sheets("density").Cells(1 + i, 2)
.AxisGroup = 1
.ChartType = xlColumnStacked
Select Case i
Case 1
With .Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(5, 70, 255)
'.ForeColor.RGB = RGB(190, 190, 190)
.Transparency = 0.618
.Solid
End With
Case 2
With .Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 210, 0)
'.ForeColor.RGB = RGB(50, 50, 50)
.Transparency = 0.618
.Solid
End With
Case 3
With .Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(201, 137, 9)
'.ForeColor.RGB = RGB(10, 10, 10)
.Transparency = 0.618
.Solid
End With
Case 4
With .Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(226, 30, 203)
' .ForeColor.RGB = RGB(150, 150, 150)
.Transparency = 0.8
.Solid
End With
End Select
End With
Next i
For j = 1 To 6
With .SeriesCollection.NewSeries
.Values = Range(Sheets("density").Cells(5 + j + k + z, d - 11), Sheets("density").Cells(5 + j + k + z, d))
.XValues = Range(Sheets("density").Cells(1, d - 11), Sheets("density").Cells(1, d))
.Name = Sheets("density").Cells(5 + j + k + z, 2)
.ChartType = xlLineMarkers
.MarkerSize = 5
.AxisGroup = 2
Select Case j
Case 1
.MarkerStyle = xlMarkerStyleDiamond
.MarkerSize = 5
With .Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(5, 70, 255)
.Weight = 2.5
End With
Case 2
.MarkerStyle = xlMarkerStyleDiamond
.MarkerSize = 5
With .Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 210, 0)
.Weight = 2.5
End With
Case 3
.MarkerStyle = xlMarkerStyleDiamond
.MarkerSize = 5
With .Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(201, 137, 9)
.Weight = 2.5
End With
Case 4
.MarkerStyle = xlMarkerStyleDiamond
.MarkerSize = 5
With .Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(226, 30, 203)
.Weight = 2.5
End With
Case 5
.MarkerStyle = -4142
With .Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 62, 58)
.DashStyle = msoLineLongDash
.Weight = 2.5
End With
Case 6
.MarkerStyle = -4142
With .Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 62, 58)
.Weight = 2.5
End With
End Select
With mychart.Chart.Axes(xlValue, xlPrimary)
.TickLabels.Font.Size = 16
' .HasTitle = True
' .AxisTitle.Text = "Move"
' .AxisTitle.Orientation = xlVentical
' .AxisTitle.Font.Size = 16
End With
With mychart.Chart.Axes(xlValue, xlSecondary)
.TickLabels.Font.Size = 16
End With
With mychart.Chart.Axes(xlCategory)
.TickLabels.Font.Size = 16
End With
With mychart.Chart
.HasLegend = True
.Legend.Font.Size = 11
.Legend.Position = xlLegendPositionTop
End With
End With
Next j
End With
End With
Next k
End Sub |
|