?
Solved

How do I print?

Posted on 2004-08-30
13
Medium Priority
?
523 Views
Last Modified: 2013-12-25
I have a form.

There is one control button.

How do I make it so that when I push the button it opens Internet Explorer, goes to www.cnn.com, and prints the webpage automatically?
0
Comment
Question by:shaolinfunk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 400 total points
ID: 11939291
0
 
LVL 10

Expert Comment

by:anv
ID: 11940461
add a web browser form to ur project

to it pass the parameter as startingAddress= "www.cnn.com"
in the web browser's documentComplete event

add code to print the page..

0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 400 total points
ID: 11940859
Hi!

 - click Project -> Components, select 'Microsoft Internet Controls'
 - create Webbrowser control and a command button
 - paste this code
'---------------------------------------------------------------------------------------
Private Sub Command1_Click()
    WebBrowser1.Navigate "www.cnn.com"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, 0, 0
End Sub

Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    Me.Caption = Text
End Sub
'-----------------------------------------------------------------------------------------
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:shaolinfunk
ID: 11948003
dbrckovi gave me exactly the solution i was looking for.  
and dhaest pointed me to a really informative website that helped me to understand the webbrowser control.  thank you both.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11948126
hey guys,
one other quick question.  how do i bypass that print dialog that pops up?  i want it to automatically print to the default printer.  i don't want to have to click OK on the popup print dialog everytime.  thanks.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11948147
actually,
after i click on OK on the print dialog a new "Save PDF as" dialog consequently appears because my default "printer" is really the Adobe option that lets me output any document into .pdf form.  how do i by pass the "Save PDF as " dialog as well?
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11949713
Hi. Thanks for accepig.

To bypass Printer Dialog just use OLECMDEXECOPT_DONTPROMPTUSER flag. Like this:     ( WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0 )

But I'm not sure you can bypass Adobe's "Save PDF As..." dialog. It is called by the driver itself and Visual Basic has nothing to do with it.
However, maybe you can turn it off in driver settings.

I'm using Adobe Acrobat Distiller for printing to PDF, and in order to disable "Save As" dialog I do the following:

 Control Panel -> Printers -> right click Acrobat Distiller -> Printing Preferences -> Adobe PDF Settings tab -> uncheck Prompt for the PDF Filename

However, I have Adobe PDF Writer installed also, but it doesn't seem to have that option.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11951470
To get around the "Save PDF as..." dialog is there a way to write a script/batch file that will type in the name of the file to be saved and then hit the Enter button for me?  

Basically, I am away from the computer when the app is printing the website and I would like to be able to just pick up the printout from the printer.
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11960826
I'm confused.

Are you printing to a printer or to PDF file?

If you are printing to actual printer then using OLECMDEXECOPT_DONTPROMPTUSER flag, you won't have to press anything becouse printer dialog won't appear at all.

But if you are printing to PDF file, there is one possibility that I can think of at the moment:

 Set everything to run automaticaly.
 - disable printer dialog by using OLECMDEXECOPT_DONTPROMPTUSER
 - disable 'Save As' dialog by unchecking the appropriate checkbox in Acrobat Distiller's settings
 - disable 'confirm Overwrite dialog' also in Distiller's settings
 Basically, set Distiller so it will print allways to the same file without asking to confirm Overwriting.
 In your application, before the page is sent to the printer (Distiller), delete the PDF file if there is one and then send the page to the printer.
 After you send the page to printer, run a routine which will wait for PDF to be created. When Distiller creates the PDF file, rename it or copy it to different location.
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11960855
Another thing.

Uncheck "View the result in Adobe Acrobat" checkbox also. If you don't, then Acrobat will open and 'lock' the PDF file so you your app won't be able to delete or replace it.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11969179
Sorry for the confusion.  I want to print to the PDF file.

(Eventually I want to write a script to print the PDF file at scheduled times using Task Scheduler but that is a whole new question that I will post to this board later on).  

I am using Distiller and your solution works in bypassing the Print dialog.

But then 2 new error dialogs popup when stepping through the following code:

Private Sub Command1_Click()
    WebBrowser1.Navigate "www.cnn.com"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    Me.Caption = Text
End Sub


Error #1: (occurs while highlighting "WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0" in yellow )

Run-time error '-2147221248 (80040100)':
Method 'ExecWB' of object 'IWebBrowser2' failed

I don't know why this error occurs.  After I click on Debug and step through "WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0" the next error occurs.

Error Dialog #2:
"There was an error found when printing the document "res://C:\WINNT\System32\shldoclc.dll/dnserror.htm" to C:\Documents and Settings\All Users\Desktop\*.pdf.  Do you want to retry or cancel the job?  

I am assuming this error occurs because I haven't been given a chance to name the file since it just bypasses the "Save as PDF" dialog?

Thanks for your help.  When we solve this I will add another 100 pts to you.
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11985766
Hi dbrckovi,

Someone already helped me figure why I kept getting error #1.  Apprently I needed to add WebBrowser1.Stop when the form loads.  If you want to see the solution the URL is here:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_21119659.html

However I am still having trouble automating the "Save PDF as" using PDF Distiller or PDF Writer.  I am offering 150 pts for the solution at this URL if you want to continue.  Thanks for your help.

http://www.experts-exchange.com/Applications/Q_21119831.html

0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 11987229
Hi!

I was off-line for a few days so I wasn't able to respond.
If I figure out something, I'll tell you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question