?
Solved

Print several HTML docs in a WebBrowser

Posted on 2003-03-10
7
Medium Priority
?
675 Views
Last Modified: 2008-03-10
Hi, I want to print some HTML docs, so I load them in a WebBrowser first and then print them, this way:

WebBrowser1.Navigate HTML_Doc1   ' I load the first
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER   ' I print the first
WebBrowser1.Navigate HTML_Doc2   ' I load the second
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER   ' I print the second
...
WebBrowser1.Navigate HTML_DocN   ' I load the last
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER   ' I print the last

It would have to work, but looks like there's some problem. Some HTML docs don't get printed, but if I debug step by step it works fine.
Maybe the WebBrowser can't load all the docs so quickly?

Anyway if you know another way to print several HTML docs in a batch process it will be great!

Thanx!!
0
Comment
Question by:dannymarfil
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 8103584
Hi GeneM,

Well you can do it like this:

Private Enum FilePathStatus
    FileAndPathOK = 0
    PathOK = 1
    FileAndPathBad = 2
End Enum

Private Sub Command1_Click()
    Select Case ValidatePathAndFile(Text1.Text)
    Case FileAndPathOK
        MsgBox "OK"
    Case PathOK
        MsgBox "Bad File"
    Case FileAndPathBad
        MsgBox "Completely stuffed"
    End Select
End Sub

Private Function ValidatePathAndFile(ByVal What As String) As FilePathStatus
    If Dir(What) <> "" Then
        ValidatePathAndFile = FileAndPathOK
    Else
        strPath = Left(What, InStr(What & "\", "\"))
        If GetAttr(strPath) And vbDirectory = vbDirectory Then
            ValidatePathAndFile = PathOK
        Else
            ValidatePathAndFile = FileAndPathBad
        End If
    End If
End Function

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 8103588
Hi, %%QUESTIONER%%

Wrong thread sorry

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 8103599
Hi, %%QUESTIONER%%

You need to wait until the document has finished loading. I would suggest that you place the print instruction in the Document_Complete event of the webbrowser control, this way the document is fully loaded before you attempt to print it.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:dannymarfil
ID: 8104223
Yes, Tim, that works for one document but I want to print several in cascade, so I don't know how to load / wait / print and so several times.
0
 
LVL 3

Accepted Solution

by:
Marshawk earned 100 total points
ID: 8104909
See if this does the trick: After each navigate do a loop on the readyState. That way the complete HTMLDocument object should load.

WebBrowser1.Navigate HTML_Doc1   ' I load the first

While WebBrowser1.readyState <> READYSTATE_COMPLETE
  DoEvents
Wend

WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER   ' I print the first


Then use the same code structure for the other two.



TimCottee's documentcomplete suggestion should work fine as well.

Private Sub oBrowser_DocumentComplete(ByVal pDisp As Object, Url As Variant)

pDisp.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End Sub

There are a few gotcha's with the documentcomplete, especially if you have embedded iframes in your document and are using IE6. Basically its a good idea to check that pDisp is an HTMLDocument using typename() before using it.
 
0
 

Author Comment

by:dannymarfil
ID: 8109699
Thanks for your solution, Marshaw, it works fine.
The problem was that I needed to wait the loading of the html doc before printing it (even though they're local files), and the documentcomplete event is easy for one printing, but it's harder to control it for several printings in cascade...
I've made it with the ReadyState property and it works:

WebBrowser1.Navigate HTML_File
While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Wend
Debug.Print WebBrowser1.Document.URL  ' just to check it
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

Thanks!
0
 
LVL 3

Expert Comment

by:Marshawk
ID: 8110831
good deal!
0

Featured Post

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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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
Course of the Month10 days, 18 hours left to enroll

770 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