I'm trying to create a VBA macro for Word that inserts a field at the position of the cursor. The type of field shall depend on the text directly preceding the cursor. I find it surprisingly hard to access that text.
Here is what I've tried:
MsgBox "Text before selection: " & ActiveDocument.Range(Selection.Start - 10, Selection.Start).Text
This works fine in the main text but fails in other parts of the document (headers, footers, text frames, ...). The reason is that the range created by ActiveDocument.Range points to the main story range. Is there a way to create a Range for the story range of the Selection?