Moving images between cells in VBA

前端 未结 2 1617
心在旅途
心在旅途 2021-01-11 21:51

I have an image in cell (3,1) and would like to move the image into cell (1,1).

I have this code:

ActiveSheet.Cells(1, 1).Value = ActiveSheet.Cells(         


        
2条回答
  •  悲&欢浪女
    2021-01-11 22:05

    A quick and dirty way:

    Public Sub Example()
        MoveShape ActiveSheet.Shapes("Picture 1"), Range("A1")
    End Sub
    
    Private Sub MoveShape(ByVal shp As Excel.Shape, ByVal target As Excel.Range)
        shp.IncrementLeft -(shp.TopLeftCell.Left - target.Left)
        shp.IncrementTop -(shp.TopLeftCell.Top - target.Top)
    End Sub
    

提交回复
热议问题