Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 插入形状而不选择_Vba_Excel - Fatal编程技术网

Vba 插入形状而不选择

Vba 插入形状而不选择,vba,excel,Vba,Excel,我的一段代码遍历一系列单元格,如果某个单元格满足某些条件,则在该单元格中插入形状。这是可行的,但我想找到一种避免select的替代方法 'above - code to find satisfying cell ActWS.Activate 'Activate Sheet ActWS.Cells(rActPlan - 1, vReturnColumn).Select 'Select satisfying cell ActiveSheet.Shapes.AddShape(msoShap

我的一段代码遍历一系列单元格,如果某个单元格满足某些条件,则在该单元格中插入形状。这是可行的,但我想找到一种避免
select
的替代方法

'above - code to find satisfying cell
ActWS.Activate       'Activate Sheet
ActWS.Cells(rActPlan - 1, vReturnColumn).Select 'Select satisfying cell
ActiveSheet.Shapes.AddShape(msoShapeOval, ActiveCell.Left, ActiveCell.Top, ActiveCell.Width, ActiveCell.Height).Select
Selection.ShapeRange.Fill.Visible = msoFalse
 With Selection.ShapeRange.Line
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 255, 0)
        .Weight = 2.25
 End With
AddShape()
返回刚刚添加的shape对象,因此您应该能够使用下面的代码-然后参考
shp
而不是
选择

Dim shp as Shape
Set shp = ActiveSheet.Shapes.AddShape(msoShapeOval, ActiveCell.Left, _
                   ActiveCell.Top, ActiveCell.Width, ActiveCell.Height)

此代码删除所有
。选择
ActiveCell
引用:

With ActWs

    Dim rng as Range
    Set rng = .Cells(rActPlan - 1, vReturnColumn)

    Dim shp as Shape
    Set shp = .Shapes.AddShape(msoShapeOval, rng.Left, rng.Top, rng.Width, rng.Height)

    With shp.ShapeRange

        .Fill.Visible = msoFalse

        With .Line
           .Visible = msoTrue
           .ForeColor.RGB = RGB(0, 255, 0)
           .Transparency = 0
           .Weight = 2.25
        End With

    End With

End With