View Single Post
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 264
Default End of document paragraph symbol

On Sep 21, 3:33*pm, TestThis4x4
wrote:
How do you remove just the LAST paragraph symbol in a document? All the
others can stay but the last one needs to be removed.


I don't think the correct answer is "you can't". It is more like, if
you do then the last paragraph container just recreates itself. Mr.
Daniels is correct. The last paragraph container stores much of the
formatting information about the document.

The following example macros should illustrate.

Open a new blank document (lets call it demo doc) and type ten
paragarphs as shown below. Use the page setup dialog to change the
default margins to say (.5, .5, .5 and .5)

1
2
3
4
5
6
7
8
9
10

Carefully select and copy everything but the last paragraph mark.
Open a new document and paste the contents. The new document page
setup (margins) should be unchanged. Close the new document.

Carefully select and copy everything in demo doc including the last
paragraph mark. Open a new document and paste the contents. The new
document page setup (margins) should change to match those set in demo
doc. This is because that last paragraph mark stores page setup
information about a document.

Now with demo doc select and delete the last paragraph or run the
following code:

Sub Demo()
ActiveDocument.Paragraphs.Last.Range.Delete
End Sub

The result is:

1
2
3
4
5
6
7
8
9

The last paragraph was deleted (no code error) but the page setup
doesn't change. You can extend this demo with the following code:

Sub ScratchMacro()
Do While ActiveDocument.Paragraphs.Count 0
If Len(ActiveDocument.Paragraphs.Last.Range.Text) 1 Then
MsgBox ActiveDocument.Paragraphs.Last.Range.Text
ActiveDocument.Paragraphs.Last.Range.Delete
Else
If MsgBox("Deleting last paragraph which will automatically
recreate. Do you want to continue?", vbQuestion + vbYesNo, "End of
the Road") = vbYes Then
ActiveDocument.Paragraphs.Last.Range.Delete
Else
Exit Sub
End If
End If
Loop
End Sub

It will run indefinately or until tire of proving it otherwise as each
time the final paragraph is deleted it will recreate itself.