Solved

How do I print?

Posted on 2004-08-30
13
512 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
13 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 100 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 100 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
using web browser with BING 40 132
Recommendation vb6 to vb.net or others 14 177
which modules are active in VB6 project? 6 43
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

828 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