shobhit jain
shobhit jain

Reputation: 141

Replicate an object in powerpoint using vba?

I want to replicate an selected object in powerpoint using VBA code. I have a following code mention below

    Sub CopySizeAndPosition()

    ' Usage: Select two shapes. The size and position of
    ' the first shape selected will be copied to the second.

    Dim w As Double
    Dim h As Double
    Dim l As Double
    Dim t As Double

    With ActiveWindow.Selection.ShapeRange(1)
        w = .Width
        h = .Height
        l = .Left
        t = .Top
    End With
    With ActiveWindow.Selection.ShapeRange(2)
        .Width = w
        .Height = h
        .Left = l
        .Top = t
    End With 
End Sub

But I want to specify my value instead of getting object value. So, please help and thanx in advance!

Upvotes: 0

Views: 51

Answers (1)

Jamie Garroch - MVP
Jamie Garroch - MVP

Reputation: 2979

Assuming you have selected a single shape, you can set your values like this:

' Sets the size and position of the first shape in a selection
Sub SetShapeSizeAndPosition()
  With ActiveWindow.Selection.ShapeRange(1)
    .Width = 100
    .Height = 100
    .Left = 100
    .Top = 100
  End With
End Sub

Upvotes: 2

Related Questions