Insert form without SELECT

Part of my code goes through a range of cells, and if some cell meets certain criteria, it inserts a figure into this cell. It works, but I would like to find an alternative approach avoiding 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
+4
source share
2 answers

This code removes all links .Selectand 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
+5
source

AddShape()returns an object with an added shape, so you should use something like the code below - then refer to shpinsteadSelection

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

Source: https://habr.com/ru/post/1625370/


All Articles