Solved

How do I print?

Posted on 2004-08-30
13
506 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now