Printing a HTML using IE
Posted on 2005-04-25
I use the following code to print HTML files using the SHDOCVW.DLL:
Dim iSHDocIE As SHDocVw.InternetExplorer
Dim iSHDocWebBrowser As SHDocVw.WebBrowser
Set iSHDocIE = New SHDocVw.InternetExplorer
Set iSHDocWebBrowser = New SHDocVw.WebBrowser
Set iSHDocWebBrowser = iSHDocIE
iSHDocWebBrowser.Visible = False 'to enable background printing
iSHDocIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
It worked fine the first time (I sent it to a network printer and it printed without any errors). Now I get the following error:
Run-time error -2147221248
Method 'ExecWB' of object 'IWebBrowser2' failed
And when I click Debug and then continue, it prints. But I don't want this user interaction.
Can anyone tell me what is wrong with this code? A similar code in VB.Net always works like a charm for me.