vba 在特定位置插入图表对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19576582/
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
insert a chart object at a specific location
提问by user2373603
I have written a macro in excel to insert a chart. The macro is run when a particular range of cells is selected. It is:
我在excel中写了一个宏来插入图表。The macro is run when a particular range of cells is selected. 这是:
Sub drawchart2()
'
' drawchart2 Macro
'
'
Range("B24:C36").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Range("'Sheet'!$B:$C" _
)
ActiveSheet.Shapes("Chart 6").IncrementLeft 256.1797637795
ActiveSheet.Shapes("Chart 6").IncrementTop -84.2696062992
ActiveSheet.Shapes("Chart 6").IncrementLeft 54.7752755906
ActiveSheet.Shapes("Chart 6").IncrementTop -19.3820472441
End Sub
But this chart is inserted in the middle of the excel worksheet.I want to insert it onto the right top corner of the sheet.How do i Do it?
但是这个图表是插入在excel工作表的中间。我想把它插入到工作表的右上角。我该怎么做?
回答by Portland Runner
You can position it to the top easily but the right is arbitrary because someone can resize the window or scroll. Excel defaults position from upper left corner for this reason. You can get the width of the screen and do a little math but I doubt that's what you really want. Is there a set distance from the left edge or specific column you can position from horizontally?
您可以轻松地将其定位到顶部,但右侧是任意的,因为有人可以调整窗口大小或滚动。由于这个原因,Excel 默认位置从左上角开始。您可以获得屏幕的宽度并进行一些数学运算,但我怀疑这是否是您真正想要的。与左边缘或特定列之间是否有固定距离,您可以从水平方向定位?
Here is how to position from the top:
以下是从顶部定位的方法:
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
.ChartType = xlLineMarkers
.SetSourceData Source:=Range("Sheet1!$B:$C")
.Parent.Top = 0
.Parent.Left = 100
End With