Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Macro

Status
Not open for further replies.

rowhawk

Technical User
Jul 21, 2004
25
GB
I'm trying to create a macro in Word 2000 that prints the first page from tray 2 and the remaining sheets from tray 3, then I set it to print again, all from tray 3 so I get a copy.

The problem is that some of the documents have section breaks in and the first page of these section breaks prints out from tray 2 if using the current macro.

As there are alot of documents, not all with section breaks, I need to be able to have a macro that is universal for all, and can look to see if there are section breaks within the document etc.

I have tried looking at the code and using an If statement, but I'm not very good at visual basic (In fact I'm crap)so I was wondering if someone point me in the right direction on how to do this.

Any help much appreciated.

Cheers Helen
 
1. Could you post some code?

2. It is easy to find out if there are section breaks; what you may have problems with is the type of section break. Are any of them possibly going to be continuous section breaks?

You can get a section count with:
ActiveDocument.Sections.Count

However, say Page 1 has 3 continuous sections breaks - they could still be all on Page 1. According to what you want you would still want all of them to print on Tray 2.

Gerry
 
Here is some basic code,
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2)
.BottomMargin = CentimetersToPoints(3.6)
.LeftMargin = CentimetersToPoints(2)
.RightMargin = CentimetersToPoints(2)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(0)
.FooterDistance = CentimetersToPoints(0)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = 263
.OtherPagesTray = 262
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.GutterPos = wdGutterPosLeft
End With
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2)
.BottomMargin = CentimetersToPoints(2)
.LeftMargin = CentimetersToPoints(2)
.RightMargin = CentimetersToPoints(2)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(0)
.FooterDistance = CentimetersToPoints(0)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.FirstPageTray = 262
.OtherPagesTray = 262
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = True
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.GutterPos = wdGutterPosLeft
End With
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
End Sub

Basically I need the very first page in the document to have different settings than other pages in the document, and that page to print from tray 2.
All other pages including any sections need to be a different page setup and print from tray three.
However just to make things even more awkward I then need all pages in the doc, including the first page to print from tray 3, so the users get a copy, so its hard to say how many pages etc may be in a doc, by the time the user has finished with it.

The trouble is the docs are used in a case management system so we have a basic template of text etc, then the case management system puts in the rest when its generated. Because of this we would like to have a macro that we can set, so when users do the print with copy all docs print from the right tray etc.

I was wondering if it was possible to put an IF statement in, for example, if theres more than one section in a doc, do this (but not on the first page of section one), or if theres more than one page, do that, etc.

Does that make sense?

Helen
 
Yes it makes sense. But you may not need to actually check for sections. Try this.
Code:
Sub PrintChangeTray()
' // set options to Tray 2
' // print Page 1
Options.DefaultTray = "Tray2"
    Application.PrintOut FileName:="", _
     Range:=wdPrintRangeOfPages, _
     Item:=wdPrintDocumentContent, _
     Copies:=1, Pages:="1"
' // set options tp Tray 3
' // print Page 2 to end of doc
Options.DefaultTray = "Tray3"
    Application.PrintOut FileName:="", _
      Range:=wdPrintRangeOfPages, _
      Item:=wdPrintDocumentContent, Copies:=1, _
      Pages:="2-" & _
        ActiveDocument.Range.ComputeStatistics(wdStatisticPages)

' // print entire doc from Tray 3
    Application.PrintOut FileName:="", _
    Range:=wdPrintAllDocument, _
    Item:=wdPrintDocumentContent, Copies:=1, _
    Pages:="", PageType:=wdPrintAllPages
End Sub

Gerry
 
Thanks Gerry,

That looks quite promising, when I'm back in work tomorrow I'll give it a shot and let you know how I get on.

Cheers Helen
 
Hi Gerry,

First tests look promising, however I need the sections not to print the header or footer, they should only appear on the very first page.

Is this possible?

Cheers Helen
 
Again, please be careful on exactly what you mean by "sections". As stated, it is possible to have three, four, five sections on one page. So if that was true and I do not know if it IS true in your case) would you still want to print header/footer for that page - assuming it is the first page?

However, that being said, yes. you can just have the header/footer print just the first page.

You would have to have them set up that way.

Make Different First Page = ON. Now there is no way to turn HeaderFooterOddPages = OFF. there is an explanation for this, but I am going to ignore that for now. The solution is to make HeaderFooterOddpage = "" - that is, NO text. That way, it does print, but it prints blank.

If you are asking if, if there IS text for the other pages, can you supress them. yes, it is possible, but you would have to do it with code.

Gerry
 
I will have a look a the examples you have given me.

Not all documents have sections in, some have more than others etc, unless we go through every single letter (there must be over 1000) so we wanted the macro to determine before printing if there were any sections or maybe even just more than one page in the document.
The users also add additional information to these letters, so what may have been a 1 page document, could end up being 2-3 even more pages by the end of it.

Thats why I was wondering if 'If' statements would work in this case.

I do appreciate the help you are giving me.

Cheers Helen
 
Ummm. Yes IF statements could be used. I think you better be a bit more clear as to what you want to be happening.

1. So a one page document has user added text to. It is now 413 pages - from a one page document. Does this makes any difference? Your request was for a print job to do one tray for page 1, different tray for page 2 onwards. The above code could be changed to:
Code:
Sub PrintChangeTray()
' // set options to Tray 2
' // [b]print Page 1[/b]
Options.DefaultTray = "Tray2"
    Application.PrintOut FileName:="", _
     Range:=wdPrintRangeOfPages, _
     Item:=wdPrintDocumentContent, _
     Copies:=1, Pages:="1"
If ActiveDocument.Range. _
    ComputeStatistics(wdStatisticPages) > 1 Then
      ...do the stuff for printing the other pages
Else
   ' only one page, ain't no more...you are done
   Exit Sub
End If

Again, I am trying to get this things with section straight. Explain what the section relevance is??? There are types of sections. If it is a continuous section break, you can have many on ONE page...but again, who cares, as you just want to print page 1 differently. It has 117 section breaks, but still ONE page. So you are still just print that page on tray 2. There are other section breaks that make a different pages. But again, who cares, you still want to print page 1 differently.

What am I missing?

Gerry
 
Sorry if I'm not making myself very clear,

We have alot of documents that are brought across into a case plan, when it is brought across, data is merged in and sometimes users may also add additional paragraphs, so increasing the number of pages.
Some of these documents also have section breaks, for example the last page may be terms and conditions that are set out in columns, some may have more than one section break for different reasons.

We never had a problem with this until they decided to change the letter head, and bring some of the data in on a header and footer. Thing is we only need the header/footer on the very first page, and that page to print from Tray 2 (Letterhead), the rest of the pages print from tray 3 (plain), then all of the pages (including the first page) to print from tray 3 to give them the copy.

If a document has section breaks, word treats these as first pages again, and so prints the first page of the next section with the header and footer and on letterhead.

Basically, we only need headers and footers on the very first page of section one, and for this page to print to the tray with letterhead in. (This page also has a different margin setup than the rest of the pages).

It would be nice though if it could work out if there are any other pages/sections and make the changes as necessary.

Does that help?

I will have a look at the code above to see if that makes things clearer for me.

Sorry I'm a complete beginner at this.

Helen
 
Not a complaint. It is just that to help other people it is absolutely crucial to get clear consise details.

For example, you never explained the reason for Page1 going from a different tray. OK, so now i know it is a factor of header and footer. This was not mentioned before. Nor was it mentioned that there are different margins on the first page. I am not sure how significant this is, right now.

Some of these documents also have section breaks, for example the last page may be terms and conditions that are set out in columns, some may have more than one section break for different reasons.

I am still a little confused. Are you stating that you do NOT want ANY headers or footers on any page other than Page 1, and THAT only on the first print run?

Because if you are, then:

Print Page 1, then strip off the headers and footers from the other pages, then print them, as in the code above. Do you need help with stripping off the headers and footers?


Gerry
 
That would be great thanks Gerry.

We need headers and footers only on page 1 (Section 1), regardless of how many sections may be in the doc. On both print runs. The rest of the doc, has different margins, no headers and footers (including any other sections that may be in the doc)

Helen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top