Print only certain pages in Form

D

dgold82

Is there a way to make a checkbox that when checked clicking print would only
print those pages? I have a document with 50 forms in it and would like to
put a little box in the corner so that if it is checked word will only print
those pages. I figured out how to make a checkbox act like a "print this
page" type button but I am really looking for a way to check like 5-10 of
these pages and at the end just hit print and only those 5-10 print.

Any ideas?
 
G

Greg Maxey

I don't claim expertise with ActiveX type controls, but something like this
might do.

1. Put a checkbox on each page. Name the boxes Print1 - Print50. Caption
the boxes Print.

2. In your code that intercepts the print command use this:


Dim arrPrint() As String
Dim oILS As InlineShape
Dim oCtr As Object
Dim i As Long
Dim strPrint As String
i = 0
For Each oILS In ThisDocument.Range.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If InStr(oILS.OLEFormat.Object.Name, "Print") > 0 Then
If oILS.OLEFormat.Object.Value = True Then
ReDim Preserve arrPrint(i)
'Put the number part of the control name in the array.
arrPrint(i) = Right(oILS.OLEFormat.Object.Name,
Len(oILS.OLEFormat.Object.Name) - 5)
i = i + 1
End If
End If
End If
Next oILS
strPrint = Join(arrPrint, ",")
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPrint
 
D

dgold82

Thanks Greg. I can't seem to get it to work. How to I write code that
"intercepts the print command"? Sorry--I am beginning to find out that I am
not as good with Word as I previously thought.
 
G

Greg Maxey

Option Explicit
Dim arrPrint() As String
Dim oILS As InlineShape
Dim oCtr As Object
Dim i As Long
Dim strPrint As String
Sub FilePrint()
i = 0
For Each oILS In ThisDocument.Range.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If InStr(oILS.OLEFormat.Object.Name, "Print") > 0 Then
If oILS.OLEFormat.Object.Value = True Then
ReDim Preserve arrPrint(i)
arrPrint(i) = Right(oILS.OLEFormat.Object.Name,
Len(oILS.OLEFormat.Object.Name) - 5)
i = i + 1
oILS.OLEFormat.Object.Caption = ""
oILS.Width = 0.1
oILS.Height = 0.1
End If
End If
End If
Next oILS
strPrint = Join(arrPrint, ",")
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPrint
For Each oILS In ThisDocument.Range.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If InStr(oILS.OLEFormat.Object.Name, "Print") > 0 Then
oILS.OLEFormat.Object.Caption = "Print"
oILS.Width = 40
oILS.Height = 15
End If
End If
Next oILS
End Sub
Public Sub FilePrintDefault()
i = 0
For Each oILS In ThisDocument.Range.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If InStr(oILS.OLEFormat.Object.Name, "Print") > 0 Then
If oILS.OLEFormat.Object.Value = True Then
ReDim Preserve arrPrint(i)
arrPrint(i) = Right(oILS.OLEFormat.Object.Name,
Len(oILS.OLEFormat.Object.Name) - 5)
i = i + 1
oILS.OLEFormat.Object.Caption = ""
oILS.Width = 0.1
oILS.Height = 0.1
End If
End If
End If
Next oILS
strPrint = Join(arrPrint, ",")
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPrint
For Each oILS In ThisDocument.Range.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If InStr(oILS.OLEFormat.Object.Name, "Print") > 0 Then
oILS.OLEFormat.Object.Caption = "Print"
oILS.Width = 40
oILS.Height = 15
End If
End If
Next oILS
End Sub
 
D

dgold82

Wow, thanks Greg. Unfortunately it is coming up with a compile/syntax error
and it highlighted this line:

arrPrint(i) = Right(oILS.OLEFormat.Object.Name,

I really don't know how to write any code so I am at a complete loss as to
what this means. I just opened visual basic and pasted your code below into
"ThisDocument" --did I put it in the right area?
 
G

Greg Maxey

That was due to text wrapping in the newsgroup viewer. Bring the following
line up to the end of the line throwing the error.
 
D

dgold82

It works!! Thank you!

Greg Maxey said:
That was due to text wrapping in the newsgroup viewer. Bring the following
line up to the end of the line throwing the error.
 

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