Word VBA >> VBA code to get page numbers and print multi section documents!

by danieldc » Mon, 12 Mar 2007 22:55:04 GMT

I have a nice word 2000 VBA code to get a single simple document, in
one unique section, and print it as a book (double faced paper, 2
pages per paper face, page number scheme 4-1, 2-3, 8-5, 6-7).

But when the document has more than 1 section, there is a terrible
mistake at printing pages.

If the document:
- 1st section has 4 pages (numbered 1-4)
- 2nd section more 10 pages (numbered 1-10)

When printing something like "4,1", it result in some pages, equal to
section 1 pages 1 to 4, section 2 page 4 (sort of random like :o)


What a hell this kind of stupid feature called "section print" (have a
look at "help printing sections") !!!


What I asked is:

1) in a single section document, is it possible to make an Index at
document 5th page, but showing there "page number = 1" ???

2) what is the correct / better way to handle/print multi section
documents ?


Thanks, yours,
Daniel, from Brazil



Word VBA >> VBA code to get page numbers and print multi section documents!

by Jean-Guy Marcil » Mon, 12 Mar 2007 23:31:30 GMT


danieldc was telling us:
danieldc nous racontait que :


It is not because it is causing you grief that it is stupid ;-)


Insert a "Next Page" section break where the Index stars and restart page
numbering at 1.


What code are you using now to print your pages?
In your caese, you mignt ned something like:

p4s1,p1s1, etc.

To make sure that Word prints the proper "Page 1" when you have more than
one "Page 1" in the document, use "pxsy" where p = "page" and s = "section".

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
XXXX@XXXXX.COM
Word MVP site: http://www.word.mvps.org





Word VBA >> VBA code to get page numbers and print multi section documents!

by danieldc » Tue, 13 Mar 2007 03:41:53 GMT

Hello, thanks for all.



Oh, no, those puppy helpers (dog, mimi, clip, einsten) are so good,
the best ever made since the pre-windows BOB.
Too much I need to search at google to find what could really be
there, easy, at the "CHM" help system that has a search feature worst
than... well...



Yes, using sections and all that mess, it works, but add some problem
to the code to print the pages (as below)




Yes, that I had just included at the code, but it makes range property
(wdPrintRangeOfPages) of the Print Dialog (wdDialogFilePrint) really a
long long string...

Is there another way?



VBA code to get page numbers and print multi section documents!

by Jean-Guy Marcil » Tue, 13 Mar 2007 04:02:41 GMT

danieldc was telling us:
danieldc nous racontait que :


What's wrong with long strings?
Post your code.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
XXXX@XXXXX.COM
Word MVP site: http://www.word.mvps.org




VBA code to get page numbers and print multi section documents!

by danieldc » Tue, 13 Mar 2007 04:20:22 GMT



Long strings result in error message at print dialog (9105: length


This is the code to call the printer dialog.
The "p" paramter is a list of pages like "4,1,2,3,8,5,6,7,...."
limited to 255.

If I'm going to use the sectionXpageY scheme, then, the string will be
longer!

Thanks for all attention,
yours, Daniel

Private Sub dprint(ByRef p As String)
Dim myd As Dialog
Set myd = Dialogs(wdDialogFilePrint)
myd.Range = wdPrintRangeOfPages
myd.pages = p

myd.FileName = ""
myd.Collate = True
myd.Background = True
myd.PrintToFile = False
myd.PrintZoomColumn = 2
myd.PrintZoomRow = 1
myd.PrintZoomPaperWidth = 0
myd.PrintZoomPaperHeight = 0
End Sub





VBA code to get page numbers and print multi section documents!

by Jean-Guy Marcil » Tue, 13 Mar 2007 07:09:56 GMT

danieldc was telling us:
danieldc nous racontait que :


In that case you can only specify about 50 pages in your string.


But if the goal is to print as a book, I guess you are using a printer that
can handle duplex printing, right? In that case I do not understand why you
need to specify each page in a specific order like you are doing.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
XXXX@XXXXX.COM
Word MVP site: http://www.word.mvps.org




VBA code to get page numbers and print multi section documents!

by danieldc » Tue, 13 Mar 2007 20:27:38 GMT

>


If I had a printer that can handle duplex, or if I had found a printer
driver that could handle it, well, of course I would not having all
this trouble about VBA, Word page numbers, sections, and so on...

Using a simple printer, not too much, only capable of print at only
one paper page, then, get all papers, put face down, print again, and
voil the 4 pages format A5 in a A4 sheet looks like a book...


Let me ask about the code "doc.PrintOut Range:=wdPrintRangeOfPages,
pages:="4,1,2,3"
Is the "pages" paramter limited to 255 chars?
Well, this could be a solution... not user friendly, as is direct
print, but it's ok...

Thanks!



VBA code to get page numbers and print multi section documents!

by Jean-Guy Marcil » Tue, 13 Mar 2007 22:39:31 GMT

danieldc was telling us:
danieldc nous racontait que :


Are you printing on A4?
If so, why can't you just print all the odd pages, then turn the stack
around and print the even pages?
Sorry, but unless you are printing two pages at once on an A5 page and then
folding them to get a "bound" book that only needs to be stapled.... I do no
understand why you are going through all this trouble.

And even if you are doing this folding technique, if you have too many pages
(I'd say more than 16), when you fold them, they do not fit as the inner
pages (7-8,9-10) stick out more than the outer pages (1-2,15-16), you then
have to trim those, thus reducing the outside margin space. So overall, the
look is far from professional.
Also, if you are printing two A4 pages per A4 page, isn't the typo a bit too
small to be readable without causing strain on the reader's eyes?

>> >> Let me ask about the code "doc.PrintOut Range:=wdPrintRangeOfPages, >> pages:="4,1,2,3" >> Is the "pages" paramter limited to 255 chars?

Afraid so.
>> Well, this could be a solution... not user friendly, as is direct >> print, but it's ok...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
XXXX@XXXXX.COM
Word MVP site: http://www.word.mvps.org




VBA code to get page numbers and print multi section documents!

by danieldc » Wed, 14 Mar 2007 03:29:10 GMT

Hi, thanks for you comments.

Well, the "p" string was made of number pages in a scheme
"4,1,2,3" (then 8,5,6,7, then 12,9,10,11).
Of course I was alread printing first the pages up: 4,1, 8,5,
12,9... Then after the pages down: 2,3, 6,7, 10,11...
The code to generate strings already had done with the limited 255
length, working in chunks.

Now, at a document with sections, the problem is that page "1" could
be not so clear (section 1 page 1, section 2 page 1).
Then I must convert the code to use pageXsectionY scheme at the
strings, and because this, strings get longer and longer.

Unfortunately, the code ActiveDocument.PrintOut
Range:=wdPrintRangeOfPages, pages:=p also has the 255 length
limitation at string "p" to pages paramter.

Well... I'm still thinking about it...

----------------------------------------------------------------

To make clear what I'm just printing:
I get a long word document unformatted or bad formatted (no
consistency at use of styles).
Then I have a code to list all paragraphs and styles. This another
code is capable of automatic applying styles to titles1-5, normal and
textblock paragraphs. After this I create an index at page 1.

But, if I want to make some pages to be the "1st/front page" and "last
page", without page numbers, I tried using sections. And with
sections, the print simple scheme goes down! I could also create
another document, easy, but then I must stay with 2 files and not a
single one...

The document is formatted as "page size: A5, 2 pages per sheet,
margins less than 1 inch, font size something like arial/times 10-12".
There is no resizing/zoom done by printer, as the WYSIWYG is perfect
and working well.


Then, you may ask, what do I get printing 2x A5 pages into a single
A4 ?

If the paper upper face has pages 4,1 and the down face has pages 2,3,
when folded it looks like a book, really! :o)
This is far better to read than a big size A4 page full of text. I can
join all pages and make a small pack (what is not true with big A4/
letter sheets).


Thanks again for all support,
and sorry for my bad english...

Yours, Daniel
from Brazil




VBA code to get page numbers and print multi section documents!

by Ed » Wed, 14 Mar 2007 05:08:51 GMT




Daniel, it would seem that if
then you simply need to print smaller batches of pages.
Using "p11,s11-p11,s11;" you have 14 characters per print
range. That gives you batches of 18 pages per string
(252 characters total). Running the print command a few
more times may take extra time, but if you've got a
small basic printer, it may be glad for a bit of a break!

That's all I've got to think of. Good luck.
Ed



Similar Threads

1. Printing document - getting number of total pages

Hi all;

I have one small app. written in vb.net and somewhere i create one
document which can be printed using one printdialog.

Before printing it, i want to advise user's from the number of pages
of the document giving them a chance to cancel the printing operation
if they want to.

How can it be done? I've tryed searching in PrintDialog,
PrintDocument, PreviewPrintController and PreviewPageInfo and didn't
found anything about it! I've done some google search and no one seems
to have this problem. Is there some way to workaround this or do i
have to use some Windows API? If so, which API and how can i use it?

I think i'm missing something here! It seems very obvious to me.

Please help or point me to the right direction!

Thanks in advance!

2. VBA code to get page numbers and print multi section documents!