【问题标题】:excel vba multiple charts in new sheet新工作表中的excel vba多个图表
【发布时间】:2016-08-01 09:21:07
【问题描述】:

我在准备宏时遇到问题,该宏会在工作表中选择 3 个范围,然后从该数据中创建包含 3 个图表的新工作表。我该如何准备一份? 这是我目前拥有但不起作用的内容:ActiveChart.Location Where:="Inwestycje wykresy" 突出显示并出现“类型不匹配”错误。 我是否还必须包括图表尺寸和位置? 这是我的代码:

Sub InwestycjeWykresy()
Range("B3:N5").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Inwestycje").Range("B3:N5"), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Inwestycje wykresy"
With ActiveChart
    .HasTitle = True
    .ChartTitle.Characters.Text = "Alerty"
End With
Worksheets("Inwestycje").Activate
Range("B6:N7").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Inwestycje").Range("B6:N7"), PlotBy:=xlRows
ActiveChart.Location Where:="Inwestycje wykresy"
With ActiveChart
    .HasTitle = True
    .ChartTitle.Characters.Text = "Eskalacje"
End With
Worksheets("Inwestycje").Activate
Range("B8:N10").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Inwestycje").Range("B8:N10"), PlotBy:=xlRows
ActiveChart.Location Where:="Inwestycje wykresy"
With ActiveChart
    .HasTitle = True
    .ChartTitle.Characters.Text = "Nadzor"
End With
End Sub

【问题讨论】:

    标签: vba excel charts macros


    【解决方案1】:

    第二次和第三次尝试添加到现有工作表时,您需要执行ActiveChart.Location Where:=xlLocationAsObject, Name:="Inwestycje wykresy"

    我没有尝试过,但this 暗示这将是正确的语法。


    在您进一步围绕定位的 cmets 中,您将需要以下内容:

    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Alerty"
        With .Parent
            .Height = 325
            .Width = 500
            .Top = 100
            .Left = 100
        End With
    End With
    

    【讨论】:

    • 感谢蒂姆,它解决了我的错误!但是,现在我将这 3 个图表放在一张新工作表中,但它们的位置不正确 - 第一个覆盖整张工作表,另外两个很小并且相互覆盖。可能我需要包含一些关于它们的大小和位置的信息
    • This 详细介绍了实现这一目标的最佳方法。
    • 我将此添加到每个图表中 ActiveChart.Parent .HasTitle = True .ChartTitle.Characters.Text = "Alerty" .Height = 325 ' resize .Width = 500 ' resize .Top = 100 ' 重新定位.Left = 100 ' 重新定位结束于
    • 你必须改变每一个的顶部和左侧,否则它们都在同一个地方。
    • 但我有错误:'对象不支持此属性或方法'并突出显示 .HasTitle = True
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    相关资源
    最近更新 更多