【问题标题】:VBA, Excel: how to add a chart into a selected rangeVBA,Excel:如何将图表添加到选定范围内
【发布时间】:2021-07-23 14:50:46
【问题描述】:

我正在尝试将图表添加到我选择的范围内。我遇到了一些问题,找到了正确的方法。我有办法按照以下方式做某事

Dim cht as ChartObject
Dim UserSelection as Range

Set UserSelection = ActiveSheet.Selection
Set cht = ActiveSheet.ChartObjectsy.Add(UserSelection)

尝试设置 cht 变量会引发错误。我真的在寻找如何添加到我选择的范围内。 提前致谢

【问题讨论】:

  • 你真的有ChartObjectsy 还是你的问题中有错字?
  • 我猜是ChartObjects.Add(UserSelection.Left, yourdesiredwidthinpoints)

标签: excel vba charts range add


【解决方案1】:

像这样:

Dim co, cht as Chart
Dim UserSelection as Range

Set UserSelection = ActiveSheet.Selection

'add a chartobject
Set co = UserSelection.Parent.Shapes.AddChart2(240, xlXYScatter)
co.Name = "myChart"
co.Top = UserSelection.Top 
co.Left = UserSelection.Left
co.Width = 400
co.Height = 400

Set cht = co.Chart 'the contained chart

【讨论】:

    猜你喜欢
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多