热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ExcelVBA图表自动形状左上角位置-ExcelVBAChartAutoShapeTopLeftPosition

IhaveachartinExcel.Iveaddedashapetothechartwith:我在Excel中有一个图表。我在图表中添加了一个形状:excelCha

I have a chart in Excel. I've added a shape to the chart with:

我在Excel中有一个图表。我在图表中添加了一个形状:

excelChart.Shapes.AddShape(msoShapeRectangle, 0, 0, excelChart.ChartArea.width, 15)

Chart with shape

I selected the green box and ran the below macro:

我选择了绿色框并运行下面的宏:

Sub Macro6()

    Selection.ShapeRange.Left = 0
    Selection.ShapeRange.Top = 0

End Sub

I was expecting the green box to be positioned flush in the top left of the orange chart area, but as you can see there seems to be some kind of margin before the top/left zero coordinate starts..

我期待绿色框在橙色图表区域的左上方齐平,但正如您所看到的那样,在顶部/左侧零坐标开始之前似乎存在某种边距。

How can I programmatically position the green box flush in the corner?

如何以编程方式将绿色框放在角落里?

1 个解决方案

#1


1  

Try using IncrementLeft and IncrementTop.

尝试使用IncrementLeft和IncrementTop。

Sub AddBox()
    Dim cht As Chart

    Set cht = Worksheets(1).ChartObjects(1).Chart

    With cht.Shapes.AddShape(msoShapeRectangle, 0, 0, cht.ChartArea.Width, 15)
        .Name = "MyShape"
        .IncrementLeft -5  //Experiment with number to get desired effect
        .IncrementTop -5
    End With
End Sub

推荐阅读
author-avatar
549696530_c1f5e8
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有