Solved

How do I print?

Posted on 2004-09-05
11
504 Views
Last Modified: 2013-12-25
Here's my 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

I get the following error message with the "WebBrowser1.ExecWB" line highlighted in yellow:
Run-time error '-2147721248 (80040100)':
Method 'ExecWB' of object 'IWebBroser2' failed

Why?
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
  • 6
  • 3
  • 2
11 Comments
 
LVL 20

Expert Comment

by:hes
ID: 11984593
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11984676
Yeah MSDN was the first thing I checked.  But,  I didn't use any of the OLECMDID values they mentioned so I still don't understand how to get rid of the error.  Can you show me how?
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11984731
Do you have Option Explicit at the top of the form?
0
Industry Leaders: 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: 11984889
I did not.

But I added the line "Option Explicit" to the top of the form
and still geot the same error.
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11985047
I tried your code on my machine and it works ok. I get the print dialog up as you would expect.
Do you get this far?
0
 
LVL 20

Expert Comment

by:hes
ID: 11985319
Have you tried this (from msdn)

Dim eQuery As OLECMDF       'return value type for QueryStatusWB

      On Error Resume Next
      eQuery = WebBrowser1.QueryStatusWB(OLECMDID_PRINT)  'get print command status
      If Err.Number = 0 Then
                If eQuery And OLECMDF_ENABLED Then
                    WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, "", ""    'Ok to Print?
              Else
                    MsgBox "The Print command is currently disabled."
                End If
      End If
      If Err.Number <> 0 Then MsgBox "Print command Error: " & Err.Description
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11985328
No.

Try saving and closing your project.  Then close your VB editor.
Then re-open the VB Editor and re-open the project.  Then do Ctrl + F5 to "Start with Full Compile".  Did the app still run without any errors?
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11985334
Hi hes,

I pasted your code this way and got a "permission denied" error..

Private Sub Command1_Click()
    WebBrowser1.Navigate "www.cnn.com"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Dim eQuery As OLECMDF       'return value type for QueryStatusWB

     On Error Resume Next
     eQuery = WebBrowser1.QueryStatusWB(OLECMDID_PRINT)  'get print command status
     If Err.Number = 0 Then
              If eQuery And OLECMDF_ENABLED Then
                  WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, "", ""    'Ok to Print?
            Else
                  MsgBox "The Print command is currently disabled."
              End If
     End If
     If Err.Number <> 0 Then MsgBox "Print command Error: " & Err.Description

End Sub

Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
    Me.Caption = Text
End Sub
0
 
LVL 20

Accepted Solution

by:
hes earned 75 total points
ID: 11985392
Ok your code did work for me until I tried your suggestion of saving then reopening and Ctrl + F5 , Got the same error.
Add this

Private Sub Form_Load()
  WebBrowser1.Stop
End Sub

The webbrowser control in compiled mode tries to access the internet at form load complete, thus the error, no web page to print.
I also changed this because I was gettint about 6 printer dialog boxes displayed

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If WebBrowser1.ReadyState = READYSTATE_COMPLETE Then
      WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, 0, 0
    End If
End Sub
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11985692
Thanks for explaining why it wasn't working.  The .Stop code solves the problem, no more errors.  
0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 11985838
Is there a way to set WebBrowser1.Visible = False and still have this code work i.e. still print?


0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 1,069
Prevent checkbox click event occur while editing it in vb6 8 75
Recommendation vb6 to vb.net or others 14 241
VB6 Enviroment 3 37
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

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