How to achieve printing of the particular selection of pages (25-30 for example) with the macro combined with the msgbox prompting for the desired page range?
How to achieve printing of the particular selection of pages (25-30 for example) with the macro combined with the msgbox prompting for the desired page range?
Why do you want a messagebox prompting for the page range? Will they know it? I thought you wanted to print a Section?
[vba]ActiveDocument.PrintOut Pages:="s2"[/vba]prints Section2. Regardless of the number of pages, or their page numbers.
Hoo boy... have you done searches on this particular topic? The concept of "pages" in Word is a very nebulous one.
Did you know you can manually print a page range using the File > Print dialog? P25-P30 typed manually into that dialog will do what you're trying to achieve.
From there, you could try recording that macro to see what the code is.
Why don't you try that (and perhaps do some searches on how pages vs. sections work in this forum and others) and that should give you some background.
It's a big topic, and I don't really want to rehash that discussion when it already exists on this forum multiple times.
Excellent question. To shorten the way of ctrl+p, page range 25-30 etc.Originally Posted by fumei
Except if you want to just print the section there is no need.
Perhaps, but I would still like to see if it is possible.Originally Posted by fumei
I tried to create it myself but doesn't seem to work
[VBA]lCopiesPrintFrom = InputBox( _
Prompt:="From which page?", _
Title:="Page Range", _
Default:="20-25")[/VBA]
Try recording a macro in which you print page 5 only.
_______________________________________________
Please don't cross-post without providing links to your cross-posts. We answer questions for free. Please don't waste the time of the people helping you.
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
- Frosty
Originally Posted by Frosty
[VBA]ActivePrinter = "Microsoft XPS Document Writer"
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="5", PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub[/VBA]
It is absolutely possible.
Take a good look at the difference between your code for page 5 and
[vba]lCopiesPrintFrom = InputBox( _
Prompt:="From which page?", _
Title:="Page Range", _
Default:="20-25") [/vba]
Originally Posted by fumei
I am not certain what to put insted of lCopiesPrintFrom.
Something that would mark range, but what..?
Ummmm, is not - from the recorded macro - page 5 in the, ummmm, Pages parameter?
PrintRangeOfPages?Originally Posted by fumei
I don't know what else.
Where the number "5" is, is where you'd put you string. But you should read the print dialog to see the allowed strings you can give it
This is the way to learn. See what you can do manually. Then record it. Then manually modify.
_______________________________________________
Please don't cross-post without providing links to your cross-posts. We answer questions for free. Please don't waste the time of the people helping you.
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
- Frosty
Make a string variable.
Make it equal the result of your inputbox.
Use it with the Pages parameter.
It is a good idea to read up on the printout methgod.
Interesting concept - methgod. Sounds like something a terminal alcoholic might pray to.Originally Posted by fumei
Cheers
Paul Edstein
[Fmr MS MVP - Word]
Do you have an example of how the string variable should look like?Originally Posted by fumei
Zack, you hve to do the work on this. The concept of pages in word is really tricky. There is no perfect generic solution. So you have to figure out what is going to work for your documents, and how to adjust the code for your documents.
We're not trying to be obtuse, but if you did a search on just this forum, you would see numerous examples.
The best way for you to figure this out, is to go from that recorded macro that prints out just page 5, to a recorded macro that prints out pages 5 & 6. Try to do it manually, until you get it to work, and then record the macro.
Compare that from the one that just printed out page 5... And you'll be pretty close to *your* solution for this tricky problem. But it's only your solution. Printing specific pages is a hard topic.
_______________________________________________
Please don't cross-post without providing links to your cross-posts. We answer questions for free. Please don't waste the time of the people helping you.
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
- Frosty
I am not a VBA expert, hopefully there is a solution to this issue.
If it can't be wrote in VBA or if it would take too much time and effort to create it let it go.
I was curious, but I understand you people have lives. You can't spend 10 hours writing VBA codes, especially since Frosty says it's hard.
I am not a VBA expert, hopefully there is a solution to this issue.
You do not need to be an expert as this is quite basic. There is no hope involved. There IS a solution.
If it can't be wrote in VBA or if it would take too much time and effort to create it let it go.
It most certainly can be written in VBA, and no it does not take a lot of effort. But it does take SOME effort on your part.
I was curious, but I understand you people have lives. You can't spend 10 hours writing VBA codes, especially since Frosty says it's hard.
Curiosity is good...follow that. While dealing with pages themselves is a bit convoluted (which is what I think Frosty is mentioning), what you are trying to do is not hard at all.
You want to - if I understand correctly - have a variable (taken from an inputbox) used in printing.
Frosty - "Printing specific pages is a hard topic." Ummmmm, not in this case. If the specific pages are numeric i.e. pages 5-7. Identifying specific pages can be difficult yes. But if it is simply I want to print pages 5-7, or 20-25, I would have to disagree - that is not hard.
Zack, look up Inputbox in Help. This shows you how to declare a variable (MyValue), and how to make that equal the result of the Inputbox. Now use it
[vba]ActiveDocument.PrintOut Pages:=MyValue[/vba]
macropod - not sure an alcoholic moving to meth is a good idea...