Last page _ BLANK

P

Peter KNAP

I have problem with this macro:

Dim i As Long
i = 5
Dim source As Document, target As Document
Set source = ActiveDocument
Set target = Documents.Add
target.Range.FormattedText = source.Sections(i).Range.FormattedText

After user click last button of user form just appropriate section of active
document is shown. This is perfect however problem is that it always inserts
one empty page at the end of section. I thought it is problem with formatting
of text but it is plenty of place at the end of page for text (so I think
problem is not with page or section brake).
Could somebody help?

peter
 
L

Lene Fredborg

As far as I can see, the problem is this:

The code:
source.Sections(i).Range.FormattedText
includes the section break character in case i is not the last section, and
a Section Break (Next Page) will result in a blank page after the break (turn
on formatting marks to see the section break). If i is the last section, the
code line above will result in an empty paragraph at the end of the target
document.

Try inserting the following code at the end of your code and see whether
this solves the problem:

With target
If .Sections.Count > 1 Then
'Delete the section break
.Characters(.Characters.Count - 1).Delete
Else
'Delete the last empty paragraph
.Characters.Last.Delete
End If
End With

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top