I am glad the macro works. Actually, even it the macro ended up being very
simple, it took some experiments to get there. And no, I did not have any
macro that solved the Shift+down arrow problem in Outline view. I decided to
try making one - and it ended up being rather tricky because a lot of the
information you can retrieve about position etc. seems to be unreliable in
Outline view (as also stated in the article at
http://word.mvps.org/faqs/macrosvba/GetIndexNoOfPara.htm)
However, I think I succeeded in creating a macro that - at least in my tests
- works acceptable but not perfectly. Note the following: If you run the
macro repeatedly and if the selection expands from one paragraph to another
and if the original start of the selection was to the right of the paragraph
end, the end of the next selection will stop at the same horizontal position
as the paragraph end above, i.e. the selection in the last line will be
"shorter" than it should have been (I decided to accept this). Also note that
the macro may sometimes add two lines to the selection instead of one
(because the line count is not reliable either - Word seems to base the
calculation of lines on Print Layout view). But as opposed to using
Shift+Down Arrow, the macro will at least not just extend the selection to
entire paragraph(s).
The built-in command that is executed when pressing Shift+Down Arrow is
"LineDownExtend". Correspondingly, the commands executed when using the other
arrow keys are LineUpExtend, LineRightExtend and LineLeftExtend. The NOTE in
my previous post also applies here.
Here is the macro that attempts to make LineDownExtend work "normally", also
in Outline view (note that long lines in the macro may be broken):
Sub LineDownExtend_Special()
Dim nOldLastLine As Long
Dim nNewLastLine As Long
Dim nStartPos As Long
With Selection
'If in Outline view, compensate for "wrong" selection
If ActiveDocument.ActiveWindow.View.Type = wdMasterView And
ActiveDocument.Subdocuments.Count = 0 Then
'Outline view
'Find start position of selection
nStartPos = Selection.Start
'Find line number of last selected line
nOldLastLine =
..Characters.Last.Information(wdFirstCharacterLineNumber)
'Extend selection in the normal way
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
'If start position has changed, reset to original position
If .Start <> nStartPos Then
.Start = nStartPos
End If
'If more than one line added to the selection, reset selection end
nNewLastLine =
..Characters.Last.Information(wdFirstCharacterLineNumber)
If nNewLastLine > nOldLastLine + 1 Then
.MoveEnd Unit:=wdLine, Count:=-(nNewLastLine - nOldLastLine)
+ 1
End If
Else
'If not Outline view - just move down
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
End If
End With
End Sub
If you wish macros for the other Shift+Arrow key variants, it is up to you
to create them ;-)
--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word