How to extract shape coordinates in Word VBA

I am trying to write a VBA macro in Word that will extract shapes and build them in Visio. I'm having trouble getting the XY coordinates in the document. I tried using the Top and Left properties of the form objects. The Left property seems to be working fine, but Top is not working properly. The form at the top of the page may have the same top as the form at the bottom, so the top does not seem to apply to the Y coordinate, which makes no sense to me.

Any thoughts or suggestions?

+4
source share
1 answer

John, the "Top" property should be updated as the location of the form changes. You are using a script as shown below:

Sub getShapeXY() Dim shp As Shape Set shp = ThisDocument.Shapes(1) shpOffsetX = shp.Left shpWidth = shp.Width x = shpOffsetX + shpWidth shpOffsetY = shp.Top shpHeight = shp.Height y = shpOffsetY + shpHeight Debug.Print shpOffsetX & ": OffsetX, " & shpWidth & ": Width, " & x & ": X" Debug.Print shpOffsetY & ": OffsetY, " & shpHeight & ": Height, " & y & ": Y" End Sub 
+2
source

All Articles