使用 VBA 的图表绝对位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21028126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Absolute Position of Chart Using VBA
提问by Nat Aes
I can use VBA to create a clustured column charty using the following code:
我可以使用 VBA 使用以下代码创建一个 clustured 柱状图:
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?
然而,这仅相对于其原始位置。是否可以将其设置为始终位于某个像素或单元格编号?换句话说,我可以编写 VBA 代码以在工作表的某个位置创建图表吗?
回答by Tim Williams
Use the .Top
and .Left
properties
e.g
使用.Top
和.Left
属性,
例如
With ActiveSheet.Shapes("Chart 1")
.Left = Range("C10").Left
.Top = Range("C10").Top
End With