Search code examples
vbapositionpowerpoint

How to get position of image in PowerPoint from centimeters to points with VBA


So I have an image on a slide and I need to get the position of said image in points, but I only know its position in centimeters. I need the points so that I can place another image directly over it with the following VBA code:

Set myImageBox = mySlide.Shapes.AddPicture(ActivePresentation.Path & "\X.png", False, True, xPos, yPos, -1, -1)

Where xPos and yPos are the coordinates of the image I am trying to overlay. I am a bit of a novice with VBA as far as PPT is concerned.

Any ideas?


Solution

  • You can pull the location from the existing object before you set the next one.

    You can use .Left for X

    and .Top for Y

    Example:

    xPos = yourShape.Left
    yPos = yourShape.Top
    

    Note: You will need to find the shape and assign it to an Object named yourShape for the example code to work.