Printing problem

M

Mark

I am trying to print out a selected range of pages with the below code but
the print fails to complete. Please can someone assist with a solution.

Sub Print_Guidance()
Dim i As String
Dim s As String
Dim t As String
Dim u As String
Dim v As String
Dim w As String
Dim x As String

Dim PagesToPrint As String

Application.ScreenUpdating = False

ActiveDocument.Unprotect Password:=""

Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Application.DisplayAutoCompleteTips = True
ActiveDocument.AttachedTemplate.AutoTextEntries("Guidance"). _
Insert Where:=Selection.Range, RichText:=True

ActiveDocument.Repaginate

i = ActiveDocument.BuiltInDocumentProperties("Number of Pages")

s = CStr(i - 6)
t = CStr(i - 5)
u = CStr(i - 4)
v = CStr(i - 3)
w = CStr(i - 2)
x = CStr(i - 1)
'
i = CStr(i)

PagesToPrint = s & "," & t & "," & u & "," & v & "," & w & "," & x & ","
& i

Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:=PagesToPrint,
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False

Selection.MoveUp Unit:=wdLine, Count:=377, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Sections(4).ProtectedForForms = True
ActiveDocument.Sections(5).ProtectedForForms = True
ActiveDocument.Sections(6).ProtectedForForms = False

ActiveDocument.Protect Password:="", NoReset:=True, Type:= _
wdAllowOnlyFormFields

Application.ScreenUpdating = True

End Sub
 
T

Tony Jollans

Does the document actually have pages with those numbers? You have many
sections - is page numbering restarted in any of them?
 
M

Mark

The initial document is 22 pages in length.

Page numbering is started on page 4.

The last page when the document is first opened is shown as page 19.

When the autotext is inserted the document increases to 29 pages, but there
could be more pages if a user typed a lot of text within the tables in the
document.


Mark
 
T

Tony Jollans

Well, pages i, i-1, and i-2 certainly won't exist.

Where are your autotexts (and anything else) inserted - before or after page
4? When the extra pages have been added and the document is 29 pages, say,
what is the actual page number shown on the last page?
 
M

Mark

Ok,

The autotext page are inserted at the end of the story. When I view the
header and footer and insert page numbering onto these extra pages it shows
SECTION 6 and these pages are numbered 2 to 8 respectively. How do I print
only these pages, can someone help me with some code for this, please?
 

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