jeeswg wrote:This is possibly a good alternative, it depends on how Word handles lines / 'paragraphs':
Code: Select all
q:: ;word - duplicate line (copy line above)
wdFirstCharacterLineNumber := 10
oWd := ComObjActive("Word.Application")
vLineNum := oWd.Selection.Information(wdFirstCharacterLineNumber)
vText := oWd.ActiveDocument.Paragraphs[vLineNum-1].Range.Text
vText := RTrim(vText, "`r`n")
oWd.Selection.TypeText(vText)
oWd := ""
return
I have tried that approach.
It is easy to get the current line number but very hard to go from a line number to a range. Paragraphs and lines are not the same thing when lines are wrapping.
This is the closest I found:
https://msdn.microsoft.com/en-us/vba/wo ... bject-word
which allows for something like this in VBA:
Set objLine = ActiveDocument.ActiveWindow.Panes(1).Pages(1).Rectangles(1).Lines.Item(1)
I was hoping to find a way without using Selection but had no luck. MS Word doesn't have a firm grasp on how lines are going to look until it actually renders the document through the page layout parameters. Kind of the same way a HTML file does not understand lines until it is rendered through the layout of a web browser. Lines are fluid in both. Lines are not really part of the data's structure.
Selection.Information seems to run a method to figure that stuff out, but not really a reverse method to go the other way when you have a piece of
Selection.Information and want to find the Selection.
You can use
GoTo to select a line but again I would really like to be able to work with just ranges and not selections.
Paragraphs, sentences, words, and characters are all easy to work with as they have collections that do not change regardless of page layout but that is not the case with lines.
FG