tim...
This script I found on Eric Phelps website does the trick for me.
I'll reproduce it here, slightly modified to fit the format of GA:
CODE
Dim wrd 'As Word.Application
Dim doc 'As Word.Document
Dim EndWait 'As Double
If MsgBox ("This program illustrates how to automatically
print a web page by automating Microsoft Word. BUT -- it
will only work if you installed the HTML filters for Word
and you have an internet connection! OK to continue?",
vbOkCancel) = vbCancel Then Wscript.Quit
Set wrd = CreateObject("Word.Application")
'''''''''' Remove the below line if you don't want to watch Word
wrd.Visible = True
'''''''''' Replace the web page with the one you want printed.
Set doc = wrd.Documents.Open("http://www.ericphelps.com/")
'''''''''' This is a messy kluge to give the page time to load
'''''''''' If you try to print before the page is loaded, Word crashes!
EndWait = Now + (30 / 86400) ' 30 second delay to let page load
Do Until Now > EndWait
Loop
'''''''''' Un-comment the below line if you want to use a printer
'''''''''' other than your default. If you specify a printer,
'''''''''' it must be one that is already installed on your system.
'wrd.ActivePrinter = "HP LaserJet III"
doc.PrintOut
doc.Close
wrd.Quit
Set wrd = Nothing
/CODE
The MsgBox entry will require a response, so if you know you
have the HTML filters for Word installed, you can delete it,
or comment it out, as follows:
'If MsgBox ("This program illustrates how to automatically
'print a web page by automating Microsoft Word. BUT -- it
'will only work if you installed the HTML filters for Word
'and you have an internet connection! OK to continue?",
'vbOkCancel) = vbCancel Then Wscript.Quit
As it is, the script is set to show Word's activities, but as
is noted in the script, you can remove the line which does that:
wrd.Visible = True
...or just comment it out:
'wrd.Visible = True
You might want to run through a supervised version first, with
Word visible.
If the filters are not installed, Word may ask you if you want
to install them from the internet on the spot.
And, of course, make sure you schedule it to run when you're
connected to the internet, and that your printer is turned on.
The script can be downloaded in text, vbs, or zip format, with
a readme.txt file from this page on Eric's site:
http://www.ericphelps.com/scripting/samples/PrintWebPageWithWord/index.html
Eric's other scripts for Windows can be found here:
http://www.ericphelps.com/scripting/samples/
Please do not rate this answer until you are satisfied that
the answer cannot be improved upon by way of a dialog
established through the "Request for Clarification" process.
sublime1-ga
Additional information may be found from an exploration of
the links resulting from the Google search outlined below.
Searches done, via Google:
scheduler script "print a web page"
://www.google.com/search?q=scheduler+script+%22print+a+web+page%22 |
Request for Answer Clarification by
timtitus-ga
on
01 Sep 2005 07:35 PDT
It looks like you're 90% of the way there. What do I save this
program as? I presume it should be saved as "printdoc.vbs"? How do I
call the program and enter the command line?
printdoc.vbs http://news.google.com
Will this print the web page from the command line?
|
Clarification of Answer by
sublime1-ga
on
01 Sep 2005 12:48 PDT
tim...
You asked:
What do I save this program as? I presume it should be saved as
"printdoc.vbs"?
You can name it anything you like, with a .vbs extension.
How do I call the program and enter the command line?
You mentioned wanting to use Windows Scheduler.
If you open the Windows Scheduler from the Control Panel,
one of the pages of the Wizard dialog will ask you to
navigate an Explorer-type interface and locate the program
you want to run. Just put the file is a location you
designate as its final home and point the dialog to that
location. Then follow the steps to tell Windows when and
how often to run the program.
Will this print the web page from the command line?
printdoc.vbs http://news.google.com
This question suggests to me that you didn't read the
comments included in the script, and it's very important
that you read them, as well as the comments I added.
In the script, that author notes:
'''''''''' Replace the web page with the one you want printed.
Set doc = wrd.Documents.Open("http://www.ericphelps.com/")
So you would need to change that line to the page you want
to print, as in:
Set doc = wrd.Documents.Open("http://news.google.com/")
Then you need no additional commands to run the script.
You can, indeed, run that from a command line.
Let's say you place the file as follows:
C:\batchfiles\printgoogle.vbs
You can just type that at a command line, and it will run.
Once you've satisfied yourself that the script works, by
running it with Word visible, and also giving Word a chance
to ask you if you want to update, if necessary, remember to:
'''''''''' Remove the below line if you don't want to watch Word
wrd.Visible = True
...and to eliminate the MsgBox dialog, by commenting out:
If MsgBox ("This program illustrates how to automatically
print a web page by automating Microsoft Word. BUT -- it
will only work if you installed the HTML filters for Word
and you have an internet connection! OK to continue?",
vbOkCancel) = vbCancel Then Wscript.Quit
So your final, personalized script would look like this:
CODE
Dim wrd 'As Word.Application
Dim doc 'As Word.Document
Dim EndWait 'As Double
' If MsgBox ("This program illustrates how to automatically
' print a web page by automating Microsoft Word. BUT -- it
' will only work if you installed the HTML filters for Word
' and you have an internet connection! OK to continue?",
' vbOkCancel) = vbCancel Then Wscript.Quit
Set wrd = CreateObject("Word.Application")
'''''''''' Remove the below line if you don't want to watch Word
' wrd.Visible = True
'''''''''' Replace the web page with the one you want printed.
Set doc = wrd.Documents.Open("http://news.google.com/")
'''''''''' This is a messy kluge to give the page time to load
'''''''''' If you try to print before the page is loaded, Word crashes!
EndWait = Now + (30 / 86400) ' 30 second delay to let page load
Do Until Now > EndWait
Loop
'''''''''' Un-comment the below line if you want to use a printer
'''''''''' other than your default. If you specify a printer,
'''''''''' it must be one that is already installed on your system.
'wrd.ActivePrinter = "HP LaserJet III"
doc.PrintOut
doc.Close
wrd.Quit
Set wrd = Nothing
/CODE
Save that with any name you like - printgoogle.vbs for example,
and place it where you like - C:\batchfiles\printgoogle.vbs
for example, and you're set to go.
Let me know if anything's not clear, or you have other questions.
sublime1-ga
|
Request for Answer Clarification by
timtitus-ga
on
01 Sep 2005 13:25 PDT
Sorry, but I was not clear with my request for revision: The solution
should allow me to put the URL in the command line, like:
printweb.vbs http://news.google.com
Your solution does not offer this, so it's an incomplete solution.
Can you re-code it so it can be called as previously requested?
Thanks!
|
Clarification of Answer by
sublime1-ga
on
01 Sep 2005 16:14 PDT
tim...
I apologize for the misunderstanding. In reading the original
question, it appeared that you simply wanted to be able to
regularly print a single webpage (Google News), and that it
wouldn't matter if the site address was specified in the code
or in the command line.
Is the problem that you want to be able to use the command on
such a large number of different webpages that the solution
of modifying the code to print each page isn't workable?
For example, if you're only going to use this on, say, five
different webpages, it would be relatively simple to modify
the code for each site and name the resulting file accordingly.
If, on the other hand, you expect to be using this to print
a large number of different websites, I can see why you'd be
reluctant to modify the code for that many sites.
If that's the case, I may have to ask the editors to remove
my answer and let someone else have a crack at the question,
though I doubt the specific solution you're seeking exists.
As for modifying this particular code so that the site address
goes in the command line, I don't think it can be done, since
this script necessarily performs a number of functions prior
to the address being entered, such as opening a Word document.
I can take another shot at finding an alternate script while
you respond to this post, but I'm not hopeful about there
being a solution which allows the address in the command line,
since there are several steps involved, and as mammens-ga
noted, those steps include downloading or opening the page
into some document prior to calling for the print process.
Thus I can't imagine any single script being able to do this
without first opening a document, and calling for the print
process later in the script.
Simply getting the site to open in a Word document, long
before it can be printed, requires several lines of code
before the address can be specified:
Dim wrd 'As Word.Application
Dim doc 'As Word.Document
Dim EndWait 'As Double
Set wrd = CreateObject("Word.Application")
Set doc = wrd.Documents.Open("http://news.google.com/")
...which doesn't lend itself to the idea of having the
address in the command line itself. See what I mean?
The page *has* to be opened in a document of some kind
before it a print command can be given, and even that
precludes the use of the address in the command line.
Let me know what you think, in light of this.
sublime1-ga
|
Request for Answer Clarification by
timtitus-ga
on
01 Sep 2005 17:19 PDT
Is there a way to pay for 1/2 of the answer, and I'll be 100%
satisfied? (I think I know someone who is a VB programmer who can
tell me how to "fix" this code to have the URL be an operand when the
script is run, and I'll give him the other half).
|
Clarification of Answer by
sublime1-ga
on
01 Sep 2005 17:47 PDT
tim...
Yes. You can change the price you've set on the question
by clicking on the Edit Question Parameters button, as
illustrated in this GA User's Guide created by researcher
skermit-ga:
http://www.christopherwu.net/google_answers/answer_guide.html#changing_price
If your friend is successful I'd be curious to see the
final results, and I'm sure future GA readers would be
interested, as well.
Best regards...
sublime1-ga
|
Clarification of Answer by
sublime1-ga
on
01 Sep 2005 17:56 PDT
tim...
Oops...I wasn't thinking. You can only change the question
price prior to it being answered.
The alternative would be for me to ask the editors that this
answer be removed. At that point you would have the option of
changing the price, and I could repost the answer I gave you.
I can't guarantee you that they will accept this suggestion
from me, since it would essentially mean removing an answer
that you've already benefitted from, and the decision is
ultimately theirs to make. Since there's nothing to stop
you from cancelling the question without paying anything
after the answer is removed, they may be hesitant to do so.
All I can do is make the request. Let me know if that's how
you want to proceed.
sublime1-ga
|
Clarification of Answer by
sublime1-ga
on
01 Sep 2005 19:18 PDT
tim...
For what it's worth, it may ease your conscience to know that
researchers only receive 75% of the question price anyway.
sublime1-ga
|