Я часами пытался создать макрос, который при выборе создает желаемый график. Я продолжаю получать ошибку 424, и никакие названия диаграмм, названия осей или какие-либо правки диаграммы не могут быть сделаны. Я просмотрел другие форумы и до сих пор не могу понять, что мне нужно делать. На данный момент мой макрос установлен на незаконченный график. Не уверен, что делать с кодом, связанным с моим макросом. Если бы кто-то мог провести меня через это, это было бы здорово. Ниже приведен мой код.
Sub CreateChart_Macro()
'
' CreateChart_Macro Macro
'
' Keyboard Shortcut: Ctrl+Shift+J
'
Range("K1:L30").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatterLinesNoMarkers).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$K$1:$L$30")
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MajorUnit = 0.1
ActiveChart.Axes(xlValue).MajorUnit = 0.5
With ActiveChart.Axes()
.MajorUnitIsAuto = True
.DisplayUnit = xlHundreds
End With
ActiveChart.Axes(xlValue).MaximumScale = 3
ActiveChart.Axes(xlValue).MajorUnit = 1
ActiveChart.Axes(xlValue).MaximumScale = 2.5
ActiveChart.Axes(xlValue).MinimumScale = 0
ActiveChart.PlotArea.Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.Axes(xlValue).Select
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MaximumScaleIsAuto = True
ActiveChart.Axes(xlValue).MinorUnit = 0.5
ActiveChart.Axes(xlValue).MinorUnitIsAuto = True
ActiveChart.Axes(xlValue).MinorUnit = 0.1
ActiveChart.Axes(xlValue).MinorUnit = 0.2
ActiveChart.Axes(xlValue).MajorUnit = 0.5
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 6").ScaleWidth 1.04, msoFalse, _
msoScaleFromBottomRight
ActiveChart.Axes(xlValue).Select
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes()
.MajorUnitIsAuto = True
.DisplayUnit = xlHundreds
End With
ActiveChart.Axes(xlValue).MajorUnit = 1
Selection.MajorTickMark = xlInside
Selection.MajorTickMark = xlOutside
Selection.MajorTickMark = xlNone
ActiveChart.Axes(xlValue).MinorUnit = 1
ActiveChart.Axes(xlValue).MinorUnitIsAuto = True
ActiveChart.Axes(xlValue).CrossesAt = 0
ActiveChart.Axes(xlValue).Crosses = xlAutomatic
ActiveChart.Axes(xlValue).DisplayUnit = xlThousands
ActiveChart.Axes(xlValue).DisplayUnit = xlNone
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).ReversePlotOrder = True
ActiveChart.Axes(xlValue).ReversePlotOrder = False
ActiveChart.Axes(xlValue).MajorUnit = 0.75
ActiveChart.Axes(xlValue).MajorUnit = 1
Application.WindowState = xlMinimized
Application.WindowState = xlNormal
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 6").IncrementLeft 43.8
ActiveSheet.Shapes("Chart 6").IncrementTop 1.8
ActiveChart.SetElement (msoElementDataLabelTop)
ActiveChart.SetElement (msoElementDataLabelNone)
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).MajorUnit = 6
ActiveChart.Axes(xlCategory).MajorUnit = 5
ActiveChart.Axes(xlCategory).MinorUnit = 8
ActiveChart.Axes(xlCategory).MinorUnit = 5
ActiveChart.Axes(xlCategory).MinorUnit = 5.3
ActiveChart.Axes(xlCategory).MajorUnit = 12
ActiveChart.Axes(xlCategory).MinorUnit = 10
With ActiveChart.Axes()
.MajorUnitIsAuto = True
.DisplayUnit = xlThousands
End With
ActiveChart.Axes(xlCategory).MinorUnitIsAuto = True
ActiveChart.Axes(xlCategory).MinorUnit = 2
ActiveChart.Axes(xlCategory).MinorUnit = 3
ActiveChart.Axes(xlCategory).MinorUnitIsAuto = True
ActiveChart.Axes(xlCategory).MajorUnit = 10
ActiveChart.Axes(xlCategory).MinorUnit = 3
ActiveChart.Axes(xlCategory).MinorUnit = 3.3
ActiveChart.Axes(xlCategory).MinorUnitIsAuto = True
ActiveChart.Axes(xlCategory).MajorUnit = 1
ActiveChart.Axes(xlCategory).MajorUnit = 2
ActiveChart.Axes(xlCategory).MajorUnit = 3
ActiveChart.Axes(xlCategory).MinorUnit = 0.2
ActiveChart.Axes(xlCategory).MinorUnit = 0.5
ActiveChart.Axes(xlCategory).MinorUnitIsAuto = True
ActiveChart.Axes(xlCategory).MajorUnit = 4
ActiveChart.Axes(xlCategory).MajorUnit = 5
ActiveChart.Axes(xlCategory).MinorUnit = 2
ActiveChart.Axes(xlCategory).MinorUnitIsAuto = True
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MajorUnit = 0.5
ActiveChart.Axes(xlValue).CrossesAt = 0
ActiveChart.Axes(xlValue).CrossesAt = 0.5
ActiveChart.Axes(xlValue).CrossesAt = 0
ActiveChart.Axes(xlValue).Crosses = xlAutomatic
ActiveChart.Axes(xlValue).Crosses = xlMaximum
ActiveChart.Axes(xlValue).Crosses = xlAutomatic
With ActiveChart.Axes()
.MajorUnitIsAuto = True
.DisplayUnit = xlHundreds
End With
ActiveChart.Axes(xlValue).MajorUnit = 1
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Laser Spot Diameter vs. MRR"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Laser Spot Diameter vs. MRR"
With Selection.Format.TextFrame2.TextRange.Characters(1, 27).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 23).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(24, 4).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = _
"Material Removal Rate [mm^3/s]"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Material Removal Rate [mm^3/s]"
With Selection.Format.TextFrame2.TextRange.Characters(1, 30).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 30).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.Axes(xlCategory).AxisTitle.Select
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = _
"Laser Spot Diameter [mm]"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Laser Spot Diameter [mm]"
With Selection.Format.TextFrame2.TextRange.Characters(1, 24).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 19).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(20, 5).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
ActiveChart.ClearToMatchStyle
ActiveChart.ChartStyle = 247
ActiveChart.ClearToMatchStyle
ActiveChart.ChartStyle = 245
End Sub