vba 如何使用excel vba中的“对于activesheet.shapes中的每个形状”将形状插入指定的单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20141973/
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
How to insert shape into specified cell using "for each shape in activesheet.shapes" in excel vba
提问by Ascorpio
I am asking for hint with following problem. How to add to specified cells shapes from activesheet? I am able to add shape when I know the name but don't know how to implement forumla for each shape in...
我要求提示以下问题。如何从活动表添加到指定的单元格形状?当我知道名称但不知道如何为每个形状实现forumla时,我可以添加形状...
Currently I have something like this:
目前我有这样的事情:
Sub loop()
Dim a As Integer
Dim b As Integer
Dim c As Integer
For a = 1 To 10
For b = 1 To 10
ActiveSheet.Shapes.AddShape("Shape_Name", Cells(a, b), Cells(j, k), 10).Select
Next a
Next b
End Sub
But I need something using this:
但我需要使用这个东西:
For Each Shape In ActiveSheet.Shapes
回答by
I am not sure what you need but try this
我不确定你需要什么,但试试这个
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
Debug.Print shp.Name
Next
This only iterates over the Shapes collection. So you need to have shapes in place in order to access them => logical.
这只会迭代 Shapes 集合。所以你需要有适当的形状才能访问它们 => 逻辑。
If you are trying to add shapes you can't use the for each
in .Shapes
as the .Shapes
collection would have been empty.
如果您尝试添加形状,则不能使用for each
in,.Shapes
因为该.Shapes
集合将为空。
So once you know the shapes name you can
所以一旦你知道形状名称,你就可以
Sheets("Sheet1").Shapes("Rectangle 1").Copy
Sheets("Sheet2").Select
Range("B2").Select
Sheets(2).Paste