M
Mark
I am to print some guidance for a document completion. I have the guidance
notes stored in autotext which are inserted briefly at the end of the
document so that they can be printed. Once printed they are deleted from the
document.
I have the following code:
Sub PrintGuidance()
Dim i As String
Dim s As String
Dim t As String
Dim v As String
Dim PagesToPrint As String
Application.ScreenUpdating = False
ActiveDocument.Unprotect Password:="kruger"
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Application.DisplayAutoCompleteTips = True
ActiveDocument.AttachedTemplate.AutoTextEntries("Notes_for_guidance"). _
Insert Where:=Selection.Range, RichText:=True
i = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
'i = ActiveDocument.Content.ComputeStatistics(wdStatisticPages)
s = CStr(i - 3)
t = CStr(i - 2)
v = CStr(i - 1)
i = CStr(i)
PagesToPrint = s & "-" & i
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:=PagesToPrint, PageType:= _
wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True,
Background:= _
False, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
Selection.MoveUp Unit:=wdLine, Count:=166, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=2
Call ProtectForm
Application.ScreenUpdating = True
End Sub
When the routine is stepped into it works fine, but when it is run via a
button it either produces the wrong pages or states that the printrange is
invalid.
Can anyone assist with a solution, please?
notes stored in autotext which are inserted briefly at the end of the
document so that they can be printed. Once printed they are deleted from the
document.
I have the following code:
Sub PrintGuidance()
Dim i As String
Dim s As String
Dim t As String
Dim v As String
Dim PagesToPrint As String
Application.ScreenUpdating = False
ActiveDocument.Unprotect Password:="kruger"
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Application.DisplayAutoCompleteTips = True
ActiveDocument.AttachedTemplate.AutoTextEntries("Notes_for_guidance"). _
Insert Where:=Selection.Range, RichText:=True
i = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
'i = ActiveDocument.Content.ComputeStatistics(wdStatisticPages)
s = CStr(i - 3)
t = CStr(i - 2)
v = CStr(i - 1)
i = CStr(i)
PagesToPrint = s & "-" & i
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:=PagesToPrint, PageType:= _
wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True,
Background:= _
False, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
Selection.MoveUp Unit:=wdLine, Count:=166, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=2
Call ProtectForm
Application.ScreenUpdating = True
End Sub
When the routine is stepped into it works fine, but when it is run via a
button it either produces the wrong pages or states that the printrange is
invalid.
Can anyone assist with a solution, please?