ridodds
asked on
Printing with the web browser is doubleing up on the first file
Hello All,
In the code that I will post below is what I am using to print out 'x' number of htm files with out prompting the user. It is being used inside a class that is called from an exe that is run nightly.
The main problem is that the htm file that is created first '1.htm' is printed twice and then the htm file that is created last '22.htm' is not printed at all.
I have tried various things like adding loops that just do application.doevents figureing that it will give the browser time to fully load all of the htm files but it doesn't seem to help. It just seems to fix the orginal problem but then it only prints everyother file.
The code below is what I used in the orginal version of this.
Public Sub PrintInvoice(ByVal strInvoiceHTMLFile As String, Optional ByVal strPrinterName As String = "")
' Check file exists
If Dir(strInvoiceHTMLFile) = "" Then Exit Sub
' Set printer
If strPrinterName <> "" Then
m_SetWindowsDefaultPrinter (strPrinte rName)
End If
' Load file into WebControl
m_objWebBrowser.Navigate(s trInvoiceH TMLFile)
' Wait for WebControl to load the file
Dim status As SHDocVw.OLECMDF
status = m_objWebBrowser.QueryStatu sWB(SHDocV w.OLECMDID .OLECMDID_ PRINT)
While status <> SHDocVw.OLECMDF.OLECMDF_SU PPORTED And status <> SHDocVw.OLECMDF.OLECMDF_EN ABLED And status <> 3
Application.DoEvents()
status = m_objWebBrowser.QueryStatu sWB(SHDocV w.OLECMDID .OLECMDID_ PRINT)
End While
' Send Print command
' NOTE: This print command using OLECMDEXECOPT_DONTPROMPTUS ER, sends to the Windows Default Printer
m_objWebBrowser.ExecWB(SHD ocVw.OLECM DID.OLECMD ID_PRINT, SHDocVw.OLECMDEXECOPT.OLEC MDEXECOPT_ DONTPROMPT USER)
Application.DoEvents()
End Sub
In the code that I will post below is what I am using to print out 'x' number of htm files with out prompting the user. It is being used inside a class that is called from an exe that is run nightly.
The main problem is that the htm file that is created first '1.htm' is printed twice and then the htm file that is created last '22.htm' is not printed at all.
I have tried various things like adding loops that just do application.doevents figureing that it will give the browser time to fully load all of the htm files but it doesn't seem to help. It just seems to fix the orginal problem but then it only prints everyother file.
The code below is what I used in the orginal version of this.
Public Sub PrintInvoice(ByVal strInvoiceHTMLFile As String, Optional ByVal strPrinterName As String = "")
' Check file exists
If Dir(strInvoiceHTMLFile) = "" Then Exit Sub
' Set printer
If strPrinterName <> "" Then
m_SetWindowsDefaultPrinter
End If
' Load file into WebControl
m_objWebBrowser.Navigate(s
' Wait for WebControl to load the file
Dim status As SHDocVw.OLECMDF
status = m_objWebBrowser.QueryStatu
While status <> SHDocVw.OLECMDF.OLECMDF_SU
Application.DoEvents()
status = m_objWebBrowser.QueryStatu
End While
' Send Print command
' NOTE: This print command using OLECMDEXECOPT_DONTPROMPTUS
m_objWebBrowser.ExecWB(SHD
Application.DoEvents()
End Sub
It may help to provide the loop that prints the files.
ASKER
Well this line is all I call and it is just above the End Sub of my orginal posting.
m_objWebBrowser.ExecWB(SHD ocVw.OLECM DID.OLECMD ID_PRINT, SHDocVw.OLECMDEXECOPT.OLEC MDEXECOPT_ DONTPROMPT USER)
This is what sends the command to print.
m_objWebBrowser.ExecWB(SHD
This is what sends the command to print.
ASKER
I will add that when this Sub is called it is receiving the files in order and only one copy of each. I have walked through it many times and each time the first file is only pasted in the first time and the last file is passed in as well.
Try this use timer
Option Explicit
Private Sub Timer1_Timer()
Timer1.Enabled = False
m_objWebBrowser.Navigate strInvoiceHTMLFile
End Sub
Private Sub m_objWebBrowser_DocumentCo mplete(ByV al pDisp As Object, URL As Variant)
Debug.Print pDisp
If (pDisp = m_objWebBrowser) Then
m_objWebBrowser.ExecWB(SHD ocVw.OLECM DID.OLECMD ID_PRINT, SHDocVw.OLECMDEXECOPT.OLEC MDEXECOPT_ DONTPROMPT USER)
End If
End Sub
Public Sub PrintInvoice(ByVal strInvoiceHTMLFile As String, Optional ByVal strPrinterName As String = "")
' Check file exists
If Dir(strInvoiceHTMLFile) = "" Then Exit Sub
' Set printer
If strPrinterName <> "" Then
m_SetWindowsDefaultPrinter (strPrinte rName)
End If
' Load file into WebControl
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
Option Explicit
Private Sub Timer1_Timer()
Timer1.Enabled = False
m_objWebBrowser.Navigate strInvoiceHTMLFile
End Sub
Private Sub m_objWebBrowser_DocumentCo
Debug.Print pDisp
If (pDisp = m_objWebBrowser) Then
m_objWebBrowser.ExecWB(SHD
End If
End Sub
Public Sub PrintInvoice(ByVal strInvoiceHTMLFile As String, Optional ByVal strPrinterName As String = "")
' Check file exists
If Dir(strInvoiceHTMLFile) = "" Then Exit Sub
' Set printer
If strPrinterName <> "" Then
m_SetWindowsDefaultPrinter
End If
' Load file into WebControl
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.