Excel, Vba Macro to 'move' shapes to a different shape, without copying and pasting

后端 未结 1 1203
醉话见心
醉话见心 2021-01-28 18:11

I want to move a shape to a different sheet, without using copy and paste in the macro. Is there another way to do this?

相关标签:
1条回答
  • 2021-01-28 18:11

    If the shape is a chart object, you can just change its location:

    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet2"
    

    For all other types of shapes, there is no location property or move method. If you want to avoid copying and pasting, then you'll need to create a new shape on the new sheet and copy across all relevant properties, then delete the original.

    Sub MoveShape()
    
        Dim shp1 As Shape, shp2 As Shape
    
        Set shp1 = Sheets("Sheet1").Shapes(1)
        Set shp2 = Sheets("Sheet2").Shapes.AddShape(shp1.Type, shp1.Left, shp1.Top, shp1.Width, shp1.Height)
    
        shp2.Name = shp1.Name
        shp2.Fill.ForeColor.RGB = shp1.Fill.ForeColor.RGB
        shp2.Line.Weight = shp1.Line.Weight
        shp2.Line.DashStyle = shp1.Line.DashStyle
        shp2.Line.ForeColor.RGB = shp1.Line.ForeColor.RGB
    
        shp1.Delete
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题