Paginate

L

Lisa

I am trying to format text, then paginate the document from where the
cursor originally was on forward into the text. Doing it from where
the cursor originally was is the hard part. My program JustPaginate
works well for the second part; my program FormatSelection works well
for the first part.

However when I put them together in my program Paginate, I am unable
to get the Selection in JustPaginate to only refer to the location of
the cursor. So it does not work right.

The other thing is, is I want the programs to work with any number of
original "Sections", not just one (where my InsertBreak creates a
second one).

Somehow I would like to find some way to work with an Index within
Sections or within Paragraphs, so I can go from the current location
on forward or be able to create an additional section And tell where
that section is located.


Any ideas?


Lisa







Sub FormatSelection()
With Selection
.WholeStory
.Font.Name = "Times New Roman"
.Font.Size = 8
.ParagraphFormat.Space1
End With

End Sub



Sub JustPaginate()
'
' JustPaginate Macro
'


Selection.InsertBreak Type:=wdSectionBreakNextPage

Dim prange As Range
With ActiveDocument
With .Sections(2)
Set prange = .Headers(wdHeaderFooterPrimary).Range
With .Headers(wdHeaderFooterPrimary).PageNumbers
.RestartNumberingAtSection = True
.StartingNumber = InputBox("Enter the starting page
number.")
End With
End With
.Fields.Add Range:=prange, Type:=wdFieldEmpty, Text:="PAGE"
prange.Paragraphs(1).Alignment = wdAlignParagraphCenter
End With
End Sub

Sub Paginate()
'
' Paginate Macro
'
'
FormatSelection
JustPaginate

End Sub
 
D

David Horowitz

Lisa,
Your FormatSelection sub selects the entire document, so when you get to
JustPaginate, your original Selection has been lost and your Selection is
now the whole document.
What you could do is temporarily store the Selection location, then call
FormatSelection, then reselect the original Selection, then call
JustPaginate. You could do that with something like this:
Sub Paginate()
Dim myRange As Word.Range
Set myRange = Selection.Range.Duplicate
FormatSelection
myRange.Select
JustPaginate
End Sub
Another thing you could do would be to rewrite FormatSelection so it didn't
use modify the Selection object:
Sub FormatDocument() ' renamed from FormatSelection
With ActiveDocument.Range
' don't need .WholeStory
.Font.Name = "Times New Roman"
.Font.Size = 8
.ParagraphFormat.Space1
End With
End Sub
Hope this helps - you're doing great for a "beginner"!
 

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