简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM