srinivas_vemla
asked on
Printing a HTML using IE
Hello Friends,
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.navigate "C:\Test.html"
iSHDocIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS ER
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.
Regards,
Srinivas
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.navigate "C:\Test.html"
iSHDocIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS
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.
Regards,
Srinivas
ASKER
I get this message too:
dialogArguments.__IE_Print Type is null or not an object
res://C:\\WINDOWS\System32 \shdoclc.d ll/preview .dlg
dialogArguments.__IE_Print
res://C:\\WINDOWS\System32
ASKER
Finally I get this working as:
Dim WithEvents iSHDocIE As SHDocVw.InternetExplorer
Dim WithEvents iSHDocWebBrowser As SHDocVw.WebBrowser
Private Sub Command1_Click()
Set iSHDocIE = New SHDocVw.InternetExplorer
Set iSHDocWebBrowser = New SHDocVw.WebBrowser
Set iSHDocWebBrowser = iSHDocIE
iSHDocWebBrowser.Visible = False 'to enable background printing
iSHDocIE.Navigate "C:\Temp.htm"
End Sub
Private Sub iSHDocIE_NavigateComplete2 (ByVal pDisp As Object, URL As Variant)
Retry:
If (iSHDocIE.QueryStatusWB(OL ECMDID_PRI NT) <> 0) Then
Debug.Print "YES"
Debug.Print iSHDocIE.QueryStatusWB(OLE CMDID_PRIN T)
iSHDocIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS ER
Else
Debug.Print "NO"
Debug.Print iSHDocIE.QueryStatusWB(OLE CMDID_PRIN T)
GoTo Retry
End If
End Sub
But when I use the same code to make a DLL and reference it somewhere else, i get this error:
dialogArguments.__IE_Print Type is null or not an object
This is getting me crazy... does anyone have any better ideas than this code??? something actually working????
Dim WithEvents iSHDocIE As SHDocVw.InternetExplorer
Dim WithEvents iSHDocWebBrowser As SHDocVw.WebBrowser
Private Sub Command1_Click()
Set iSHDocIE = New SHDocVw.InternetExplorer
Set iSHDocWebBrowser = New SHDocVw.WebBrowser
Set iSHDocWebBrowser = iSHDocIE
iSHDocWebBrowser.Visible = False 'to enable background printing
iSHDocIE.Navigate "C:\Temp.htm"
End Sub
Private Sub iSHDocIE_NavigateComplete2
Retry:
If (iSHDocIE.QueryStatusWB(OL
Debug.Print "YES"
Debug.Print iSHDocIE.QueryStatusWB(OLE
iSHDocIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS
Else
Debug.Print "NO"
Debug.Print iSHDocIE.QueryStatusWB(OLE
GoTo Retry
End If
End Sub
But when I use the same code to make a DLL and reference it somewhere else, i get this error:
dialogArguments.__IE_Print
This is getting me crazy... does anyone have any better ideas than this code??? something actually working????
ASKER
As a contn my previous post, the requirement is to have a code that prints HTML files using Internet Explorer object. This printing should be done without any user interaction... and the code shud be make'able into a DLL...
Please do reply if you have worked on this ever...
Please do reply if you have worked on this ever...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello EddyKT,
As suggested by you, I tried with the following code:
Dim WithEvents iSHDocWB As SHDocVw.WebBrowser
Private Sub Command1_Click()
Set iSHDocWB = New SHDocVw.WebBrowser
iSHDocWB.Navigate "C:\Documents and Settings\PN07934\Desktop\T ransform\A utoTestC.h tml"
End Sub
Private Sub iSHDocWB_DocumentComplete( ByVal pDisp As Object, URL As Variant)
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS ER
End Sub
But the error props up saying:
Run-time error '-2147477259 (80004005)'
Automation error
Unspecified error
Any ideas???
As suggested by you, I tried with the following code:
Dim WithEvents iSHDocWB As SHDocVw.WebBrowser
Private Sub Command1_Click()
Set iSHDocWB = New SHDocVw.WebBrowser
iSHDocWB.Navigate "C:\Documents and Settings\PN07934\Desktop\T
End Sub
Private Sub iSHDocWB_DocumentComplete(
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS
End Sub
But the error props up saying:
Run-time error '-2147477259 (80004005)'
Automation error
Unspecified error
Any ideas???
do this
Private Sub iSHDocWB_DocumentComplete( ByVal pDisp As Object, URL As Variant)
If (pDisp = iSHDocWB) Then
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS ER
end if
End Sub
Private Sub iSHDocWB_DocumentComplete(
If (pDisp = iSHDocWB) Then
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS
end if
End Sub
ASKER
That doesn't work either, but this works:
Dim WithEvents iSHDocWB As SHDocVw.WebBrowser
Dim WithEvents iSHDocIE As SHDocVw.InternetExplorer
Private Sub Command1_Click()
Set iSHDocIE = New SHDocVw.InternetExplorer
Set iSHDocWB = iSHDocIE
iSHDocWB.Navigate "C:\Documents and Settings\PN07934\Desktop\T ransform\A utoTestC.h tml"
End Sub
Private Sub iSHDocWB_DocumentComplete( ByVal pDisp As Object, URL As Variant)
If (pDisp = iSHDocWB) Then
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS ER
End If
End Sub
Again, if I develop an Activex DLL as:
Dim WithEvents iSHDocIE As SHDocVw.InternetExplorer
Dim WithEvents iSHDocWB As SHDocVw.WebBrowser
Public Function PrintPDF(FileName As String) As Integer
Set iSHDocIE = New SHDocVw.InternetExplorer
Set iSHDocWB = iSHDocIE
iSHDocWB.Navigate FileName
End Function
Private Sub iSHDocIE_DocumentComplete( ByVal pDisp As Object, URL As Variant)
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS ER
End Sub
And use it as:
Private Sub Command1_Click()
Dim pdfW As PDFWriter.PDFWriterClass
Set pdfW = New PDFWriterClass
pdfW.PrintPDF ("C:\Documents and Settings\PN07934\Desktop\T ransform\A utoTestC.h tml")
End Sub
I get the "dialogArguments.__IE_Prin tType" error...
Any ideas???
Dim WithEvents iSHDocWB As SHDocVw.WebBrowser
Dim WithEvents iSHDocIE As SHDocVw.InternetExplorer
Private Sub Command1_Click()
Set iSHDocIE = New SHDocVw.InternetExplorer
Set iSHDocWB = iSHDocIE
iSHDocWB.Navigate "C:\Documents and Settings\PN07934\Desktop\T
End Sub
Private Sub iSHDocWB_DocumentComplete(
If (pDisp = iSHDocWB) Then
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS
End If
End Sub
Again, if I develop an Activex DLL as:
Dim WithEvents iSHDocIE As SHDocVw.InternetExplorer
Dim WithEvents iSHDocWB As SHDocVw.WebBrowser
Public Function PrintPDF(FileName As String) As Integer
Set iSHDocIE = New SHDocVw.InternetExplorer
Set iSHDocWB = iSHDocIE
iSHDocWB.Navigate FileName
End Function
Private Sub iSHDocIE_DocumentComplete(
iSHDocWB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS
End Sub
And use it as:
Private Sub Command1_Click()
Dim pdfW As PDFWriter.PDFWriterClass
Set pdfW = New PDFWriterClass
pdfW.PrintPDF ("C:\Documents and Settings\PN07934\Desktop\T
End Sub
I get the "dialogArguments.__IE_Prin
Any ideas???
ASKER
It fails on the:
Set iSHDocIE = New SHDocVw.InternetExplorer
statement within the referenced DLL...
Set iSHDocIE = New SHDocVw.InternetExplorer
statement within the referenced DLL...
you can use webbrowser ocx on form, you still can compile as dll.
Just load the form without show
Just load the form without show
ASKER
I finally used this:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
Public Sub PrintPDF(fileName As String)
Set ieObj = CreateObject("InternetExpl orer.Appli cation")
ieObj.Visible = True
ieObj.Navigate fileName
ieObj.ExecWB 6, 2
Sleep 1000
ieObj.Quit
Set ieObj = Nothing
End Sub
This worked even after being compiled into a DLL.
Thanks guys for your replies... they were very helpful and guiding...
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
Public Sub PrintPDF(fileName As String)
Set ieObj = CreateObject("InternetExpl
ieObj.Visible = True
ieObj.Navigate fileName
ieObj.ExecWB 6, 2
Sleep 1000
ieObj.Quit
Set ieObj = Nothing
End Sub
This worked even after being compiled into a DLL.
Thanks guys for your replies... they were very helpful and guiding...
ASKER
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.Navigate "C:\Temp.htm"
Retry:
If (iSHDocIE.QueryStatusWB(OL
Debug.Print "YES"
Debug.Print iSHDocIE.QueryStatusWB(OLE
iSHDocIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUS
Else
Debug.Print "NO"
Debug.Print iSHDocIE.QueryStatusWB(OLE
GoTo Retry
End If
But not much result. I was thinking that if the file is loaded, then it should be able to be printed. But it prints only if I put a break point somewhere in the code and step thru... If I just let it run, it does nothing.
Any suggestions plssss...
Thanks,
Srinivas