I'm attempting to automate the basic process of editing text in a TextFrame in Powerpoint via Interop, and I've hit a snag. I need to be able to begin the text editing process at a particular location on screen, and after crawling MSDN I still don't know of a way to do it. The use case boils down to this:
It's the third step that's tripping me up. Word has RangeFromPoint, which returns a text range. In Powerpoint, though, that method returns a shape. I can use TextRange.Characters() to place the cursor manually within the shape's text range, but that accepts character index values rather than screen coordinates.
Anyone know how to go about this (other than brute forcing in mouse messages via Win32 calls)?
Every bit of text, down to the character level, can be treated as a Range; every text range has .BoundLeft, .BoundTop, .BoundHeight and .BoundWidth properties that return the coordinates of a rectangle that bounds the text range.
For example, this snippet will give you the left coordinate of the third text character in the currently selected shape:
With ActiveWindow.Selection.ShapeRange(1)
Debug.Print .TextFrame.TextRange.Characters(3, 1).BoundLeft
End With
Coordinates are returned in Points. It sounds like you already have a handle on converting screen coordinates to PPT coordinates.