问题
I have a .docm document with a user form. On the user form I have a button that needs to insert something (some text, for starter) at the last known cursor position in the document. For this, I want to create a range.
How can I get the starting position for this range?
回答1:
Selectionis the current position in the document.Selection.Rangeis the Range object of the currentSelection.Range.Startis the start position of aRangeobject (returns or sets a Long).
If you combine those three you get the cursor position (or the start of the selection if you have text selected):
Selection.Range.Start
If you only want to enter text att the cursor position the following will do:
Selection.TypeText "Test"
来源:https://stackoverflow.com/questions/16807860/create-range-from-current-cursor-position-word-2010-vba