PDA

View Full Version : Solved: Print pages with Objects



pimpzter
03-21-2013, 07:05 AM
I made a code that finds all pages containing oShp.Type = msoLine. Problem is that some pages have more than 1 of this shape and I only need those pages printed once. 1 nuisance is that for some reason if the shape is on page 1 it never prints page 1. The last nuisance is that the pages for some reason dont print in order so I have to sort through them after.. I think that is because the shapes are automatically numbered and depending the order the shapes were added determines the order the pages are printed. Thanks in advance for any support.


Sub PrintRevbarPages()
'Print all pages that contain msoline
Dim oShp As Shape
For Each oShp In ActiveDocument.Shapes
If oShp.Type = msoLine Then
oShp.Select
ActiveDocument.Bookmarks("\page").Select
Application.PrintOut Range:=wdPrintCurrentPage
End If
Next
End Sub

pimpzter
03-21-2013, 11:46 AM
Additionally... is there a way to get all these pages to print as 1 job total rather than a separate print job for each page ?

macropod
03-21-2013, 10:22 PM
It looks rather like you're trying to use manually-added bars to indicate document changes. A far better way would be to use 'Track Changes', with just the change bar to indicate the same thing.

As for print management, you should capture the page numbers in a string (for output to the printout command) and, for each 'found' change, check whether the current page is also the most-recent captured.

pimpzter
03-25-2013, 03:58 AM
Thanks for the input. I played around with the track changes option that adds the change bar automatically.. pretty cool function that I honestly did not know existed. The issue Im having with it is that it will add the change bar to every place that I make a change no matter how simple the change is. We use it to mark changes that affect a procedure but we do not need it to put a change bar when we do minor corrections such as changing the way a line is worded or adding a period or correcting a typo. Another issue which im sure there is a way to do this one with built in features I just dont know how is every new revision needs to have the markup wiped so only the new changes are tracked. Im sure because of the first problem I stated is why they used the manual change bars. Is there a way to capture the oShp msoLine page numbers to a string and print those pages? Thanks for the response and I appreciate any additional advice and help in advance.

pimpzter
03-25-2013, 04:07 AM
After more playing around more with what you suggested I discovered the Accept Insertion or Reject Deletion to remove the change bars. I am interested in your other suggestion of capturing the page numbers in a string (for output to the printout command) and, for each 'found' change, check whether the current page is also the most-recent captured. Thank you!

macropod
03-25-2013, 04:10 AM
The issue Im having with it is that it will add the change bar to every place that I make a change no matter how simple the change is.
The simple solution for that is to accept the trivial changes before an update is printed.

Another issue which im sure there is a way to do this one with built in features I just dont know how is every new revision needs to have the markup wiped so only the new changes are tracked.
The way I used to handle this was to archive the documents after each update, then accept all changes till then in the 'working' copies, so that only any later changes would appear in the next update. Quite simple, really.

If you're using change-tracking to add the change bars, there are no shapes to access - they're just dynamic lines drawn on the page by the software, rather like underlines and paragraph borders.

For your current setup, you'd do better to loop through all pages, checking for any msoLine shapes on the page, rather than trying to loop through all the shapes, figuring out if they're a msoLine shape, then checking whether you've already printed that page or added it to a string holding the range of pages to be printed.

pimpzter
03-25-2013, 04:18 AM
For your current setup, you'd do better to loop through all pages, checking for any msoLine shapes on the page, rather than trying to loop through all the shapes, figuring out if they're a msoLine shape, then checking whether you've already printed that page or added it to a string holding the range of pages to be printed.

Very quick response!! Thanks you for that. I like this suggestion. Exactly how do I go about doing this ?

macropod
03-25-2013, 04:38 AM
You could do that with code like:
Sub PrintChanges()
Dim i As Long, StrPrn As String, Rng As Range
With ActiveDocument
Set Rng = .Range(0, 0)
For i = 1 To .Range.Information(wdActiveEndPageNumber)
Set Rng = Rng.GoTo(What:=wdGoToPage, Name:=i)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
If Rng.Revisions.Count > 0 Then StrPrn = StrPrn & " " & i
Next i
StrPrn = Replace(Trim(StrPrn), " ", ",")
End With
With Application.Dialogs(wdDialogFilePrint)
.Range = wdPrintRangeOfPages
.Pages = StrPrn
.Show
End With
End Sub
However, this presupposes you're only interested in printing replacement pages for the ones that have been changed. That creates all sorts of issues, including what to do about parts of pages that might get duplicated and/or missed because of the repagination associated with the changes. Also, before you go/continue down that path, read: http://word.mvps.org/FAQs/Numbering/ChapterNumber.htm

I've coded the macro to always print page '1', regardless of whether it has any changes, on the assumption that's a title page.

Note also that the above doesn't take account of the effect Section breaks, with their overlapping page number ranges, can have on the printout.

pimpzter
03-25-2013, 05:08 AM
ive turned off track changes and added a few manual bars and ran this macro and it wont find any pages to print. When I turn on track changes it adds the pages with the rev bars but also the ones with basic formatting changes. Is there a way to alter it to where it does what you have done but only looks for the manual bars ive added ?.. or do I need to just keep on the track changes and accept all the changes before I run this code then it would possibly only print the pages with the manual bars.

pimpzter
03-25-2013, 06:39 AM
im trying to combine your code with the one I started this thread off with so for each oshape=msoline it stores those page numbers and prints only those pages but im having 1 heck of a time trying to combine these.

macropod
03-25-2013, 02:03 PM
The code I posted is for use with 'Track Changes' only - not for use with manual change bars. If you want more control over what gets tracked by 'Track Changes' , I suggest you adjust the 'Track Changes' options.

That said, if you're wedded to the manual line bars, try:
Sub PrintChanges()
Dim i As Long, StrPrn As String, Rng As Range, Shp As Shape
With ActiveDocument
Set Rng = .Range(0, 0)
For i = 1 To .Range.Information(wdActiveEndPageNumber)
Set Rng = Rng.GoTo(What:=wdGoToPage, Name:=i)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
If Rng.ShapeRange.Count > 0 Then
For Each Shp In Rng.ShapeRange
If Shp.Type = msoLine Then
StrPrn = StrPrn & " " & i
Exit For
End If
Next
End If
Next i
StrPrn = Replace(Trim(StrPrn), " ", ",")
End With
With Application.Dialogs(wdDialogFilePrint)
.Range = wdPrintRangeOfPages
.Pages = StrPrn
.Show
End With
End Sub

pimpzter
03-25-2013, 02:24 PM
thank you for the response. I tried your updated code and now it looks like it works like a charm.. I think its my turn to get some sleep. Thanks as always!!

macropod
03-25-2013, 03:24 PM
I suspect the issue is that the lines aren't being reported as msoLine. Try:
Sub PrintChanges()
Dim i As Long, StrPrn As String, Rng As Range, Shp As Shape
With ActiveDocument
StrPrn = "1 "
Set Rng = .Range(0, 0)
For i = 1 To .Range.Information(wdActiveEndPageNumber)
Set Rng = Rng.GoTo(What:=wdGoToPage, Name:=i)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
For Each Shp In Rng.ShapeRange
If Shp.Type = msoAutoShape Then
If Shp.AutoShapeType = -2 Then
StrPrn = StrPrn & i & " "
Exit For
End If
End If
Next
Next i
StrPrn = Replace(Trim(StrPrn), " ", ",")
End With
With Application.Dialogs(wdDialogFilePrint)
.Range = wdPrintRangeOfPages
.Pages = StrPrn
.Show
End With
End Sub