Reputation: 14787
I want to access the position and size for each indivisible unit in Microsoft Word. Examples of such units include individual characters, images, etc.
The purpose is to apply a visual overlay based on unit position and size. I will have no knowledge of the content in target documents.
Imagine the text of this question in a word document. I need to be able to iterate each character including white-space and carriage returns and get the size and position.
EDIT
It doesn't matter whether your answer considers macros, interop, add-ins or OLE embedding.
Upvotes: 2
Views: 4579
Reputation: 78210
The method which retrieves displayed coordinates of an object is Window.GetPoint
(link for the office interop version, same thing in VBA).
As for the "indivisible unit," you can put any meaning you want into that, using the available collections.
For instance, if you want it to be characters, you can use Document.Range.Characters
, which is a collection of characters, each of which is a Range
.
Or you can use Document.Range.InlineShapes
for the pictures that are part of text.
Or Document.Range.ShapeRange
to enumerate "floating" shapes.
At which point you might be thinking about Window.RangeFromPoint
to figure an object from its window coordinates.
Upvotes: 3