View Single Post
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default Word 2007 Deleting across paragraphs does not delete paragraph mar

I had not registered that strange and new behavior until reading your post. I
have not yet registered problems with any of my huge amount of macros due to
this but this could very easily happen. I agree with you that one expects the
selection to be totally deleted when one selects Delete (as it works in
previous versions of Word). The behavior could be €śby design€ť €“ e.g. to
preserve the applied paragraph styles. I cannot find any built-in options
that change the way it works.

In macros containing code to delete content that spans two or more
paragraphs without necessarily including the entire first and last
paragraphs, the only solution I can think of now is to treat the deletion via
special macro code (the problem with the left over paragraph mark applies no
matter whether you use Selection or Range when deleting). The following macro
should delete the remaining paragraph mark together with the remainder of the
selection (I have tried to make the macro so that it will not make any harm
if used in earlier versions of Word):


Sub DeleteEntireSelection_Word2007()
Dim oRange As Range
Dim nParas As Long
Dim bFirstParaIncluded As Boolean
Dim bLastParaIncluded As Boolean

Set oRange = Selection.Range

With oRange
nParas = .Paragraphs.Count

'Find out whether entire first and last paragraph is in selection
bFirstParaIncluded =
..Paragraphs.First.Range.Characters.First.InRange( oRange)
bLastParaIncluded =
..Paragraphs.Last.Range.Characters.Last.InRange(oR ange)

.Delete

'In case of Word 2007:
'If original selection spans more than 1 paragraph
'and if entire first and last paragraphs are not in the selection,
'a paragraph mark is left - delete it
If Val(Application.Version) 11 Then
'Only needed to check if more than one paragraph is selected
If nParas 1 Then
If bFirstParaIncluded = False And bLastParaIncluded = False
Then
Selection.Characters(1).Delete
End If
End If
End If
End With

'Clean up
Set oRange = Nothing
End Sub

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"ATD" wrote:

If I select from the middle of one paragraph to the middle of another
paragraph and then press Delete, I expect selection to be removed and the
remaining parts of the paragraphs to be merged into one. However, Word 2007
removes the text but inserts a paragraph mark to leave me with two paragraphs
still. This is not how it used to be and not what I want it to be but I can
not find a way to stop it doing this. It's bad enough to have to manually
delete the new paragraph mark, but we have many hundreds of templates
controlled by macros that are being badly affected by this.

How do I stop Word inserting a paragraph mark?