这个宏有什么问题,继续得到同样的错误

时间:2018-01-30 22:49:27

标签: excel vba excel-vba

我一直在努力创建一个宏来自动创建一个图形,形成一台机器的输出。我已经写下了这些步骤,并多次练习它们继续犯错并且不知道它意味着什么或者如何修复它。我有#我出错的行。我认为其余代码都很好。我使用宏录制器来创建它。

这是代码:

Macro4 Macro
'

'
    Range("I2").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$W$1086").AutoFilter Field:=9, Criteria1:="<700000"
    Range("G99:I165").Select
    Selection.ClearContents
    Range("G1:L1083").Select
    ExecuteExcel4Macro "(FALSE,227,4)"
    ActiveChart.SetSourceData Source:=Range("'Raw Data'!$G$1:$L$1083")
    ActiveSheet.Shapes("Chart 1").IncrementLeft -482
    ActiveSheet.Shapes("Chart 1").IncrementTop 113
    ActiveSheet.Shapes("Chart 1").ScaleWidth 3.2611111111, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Chart 1").ScaleHeight 1.1782407407, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Chart 1").ScaleWidth 1.0340715503, msoFalse, _
        msoScaleFromTopLeft
    ActiveSheet.Shapes("Chart 1").ScaleHeight 2.6895874263, msoFalse, _
        msoScaleFromTopLeft
    ActiveChart.Axes("xlCategory").Select

以下这一行是我的问题

    Selection.Border.Color = RGB(, , )    

    Selection.TickLabelPosition = xlLow
    ActiveChart.Axes(xlCategory).TickLabelSpacing = 1
    ActiveChart.Axes(xlCategory).TickLabelSpacing = 100
    ActiveChart.Axes("xlValue").Select
    With ActiveChart.Axes(xlValue)
        .MinimumScale = -90
        .Crosses = xlCustom
    End With
    With ActiveChart.Axes(xlValue)
        .MaximumScale = 30
        .Crosses = xlCustom
    End With
    ActiveChart.SeriesCollection(6).Select
    ActiveChart.SeriesCollection(3).Select
    ActiveChart.SeriesCollection(3).AxisGroup = 2
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SeriesCollection(3).Select
    ActiveChart.SeriesCollection(2).Select
    ActiveChart.SeriesCollection(2).AxisGroup = 2
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SeriesCollection(2).Select
    ActiveChart.SeriesCollection(1).Select
    ActiveChart.SeriesCollection(1).AxisGroup = 2
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SeriesCollection(1).Select
    ActiveWindow.ScrollColumn = 9
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 1
    Range("A1047").Select
    Selection.Copy
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartTitle.Select
    ActiveChart.Paste
    ActiveChart.ChartTitle.Text = "017306T11FluCandida            "
    Selection.Format.TextFrame2.TextRange.Characters.Text = _
        "017306T11FluCandida            "
    With Selection.Format.TextFrame2.TextRange.Characters(1, 31).ParagraphFormat
        .TextDirection = msoTextDirectionLeftToRight
        .Alignment = msoAlignLeft
    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(0, 0, 0)
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 18
        .Italic = msoFalse
        .Kerning = 12
        .Name = "+mn-lt"
        .UnderlineStyle = msoNoUnderline
        .Strike = msoNoStrike
    End With
    With Selection.Format.TextFrame2.TextRange.Characters(31, 1).Font
        .BaselineOffset = 0
        .Bold = msoTrue
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.RGB = RGB(0, 0, 0)
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 18
        .Italic = msoFalse
        .Kerning = 12
        .Name = "+mn-lt"
        .UnderlineStyle = msoNoUnderline
        .Strike = msoNoStrike
    End With
    Range("A1086").Select

1 个答案:

答案 0 :(得分:0)

您正在尝试调用ExecuteExcel4Macro "(FALSE,227,4)" - 此方法的参数应采用Function(argument1, argument2, ..)格式,具体取决于您尝试调用的宏函数。但是,您似乎省略了函数名称。

基本上,你告诉计算机“用这些价值观做点什么”,但没有给出任何关于做什么的建议。所以,它(非常自然地)对象,并抛出错误。

关于Application.ExecuteExcel4Macro方法的更多信息在MSDN上可用:https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-executeexcel4macro-method-excel(当您在要查找的功能上键入光标时,只需在VBA中点击F1)