Absolute Position of Chart Using VBA

余生颓废 提交于 2019-11-28 09:54:46

问题


I can use VBA to create a clustured column charty using the following code:

ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered

However this is normally positioned in the centre of my screen. I can have it moved using code such as the following:

ActiveSheet.Shapes("Chart 1").IncrementLeft -650.4545669291
ActiveSheet.Shapes("Chart 1").IncrementTop -295.9091338583

However this is only relative to its original position. Is it possible to set it that will always be positioned at a certain pixels or cell number? In other words can I code VBA to have create the chart in a certain position on the worksheet?


回答1:


Use the .Top and .Left properties
e.g

With ActiveSheet.Shapes("Chart 1")
    .Left = Range("C10").Left
    .Top = Range("C10").Top
End With


来源:https://stackoverflow.com/questions/21028126/absolute-position-of-chart-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!