gotcha_Crazy
06-22-2004, 08:05 AM
I'm having trouble getting the webbrowser control to print in WinXP using VB6. My Sub is as follows:
Private Sub PrintGridToHtml(grdCurrent As MSFlexGrid)
Dim txt As String
Dim r As Integer
Dim c As Integer
Dim fname As String
Dim fnum As Integer
' Make a HTML string for the grid data.
txt = "<TABLE BORDER=0 BGCOLOR=#FFFFFF CELLPADDING=3>" & vbCrLf
' Display the first row in bold italics.
txt = txt & "<TR>" & vbCrLf
For c = 0 To grdCurrent.Cols - 1
txt = txt & " <TD><B><I>" & grdCurrent.TextMatrix(0, c) & "</I></B></TD>" & vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf
' Display the rest of the rows.
For r = 1 To grdCurrent.Rows - 1
txt = txt & "<TR>" & vbCrLf
For c = 0 To grdCurrent.Cols - 1
txt = txt & " <TD>" & grdCurrent.TextMatrix(r, c) & "</TD>" & vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf
Next r
txt = "<HTML><HEAD></HEAD><BODY>" & vbCrLf & _
txt & "</BODY></HTML>"
' Save the text into a file.
fname = App.Path
If Right$(fname, 1) <> "\" Then fname = fname & "\"
fname = fname & grdCurrent.Name & ".htm"
fnum = FreeFile
Open fname For Output As fnum
Print #fnum, txt
Close fnum
'Print the file
webDesc.Navigate2 fname
webDesc.Refresh2
webDesc.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
'Kill the file
Kill fname
End Sub
It seems that sometimes it works(in debug mode) and sometimes it doesn't. If anyone has had this problem and has a fix could you let me know.
Thanks in advance.
Private Sub PrintGridToHtml(grdCurrent As MSFlexGrid)
Dim txt As String
Dim r As Integer
Dim c As Integer
Dim fname As String
Dim fnum As Integer
' Make a HTML string for the grid data.
txt = "<TABLE BORDER=0 BGCOLOR=#FFFFFF CELLPADDING=3>" & vbCrLf
' Display the first row in bold italics.
txt = txt & "<TR>" & vbCrLf
For c = 0 To grdCurrent.Cols - 1
txt = txt & " <TD><B><I>" & grdCurrent.TextMatrix(0, c) & "</I></B></TD>" & vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf
' Display the rest of the rows.
For r = 1 To grdCurrent.Rows - 1
txt = txt & "<TR>" & vbCrLf
For c = 0 To grdCurrent.Cols - 1
txt = txt & " <TD>" & grdCurrent.TextMatrix(r, c) & "</TD>" & vbCrLf
Next c
txt = txt & "</TR>" & vbCrLf
Next r
txt = "<HTML><HEAD></HEAD><BODY>" & vbCrLf & _
txt & "</BODY></HTML>"
' Save the text into a file.
fname = App.Path
If Right$(fname, 1) <> "\" Then fname = fname & "\"
fname = fname & grdCurrent.Name & ".htm"
fnum = FreeFile
Open fname For Output As fnum
Print #fnum, txt
Close fnum
'Print the file
webDesc.Navigate2 fname
webDesc.Refresh2
webDesc.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
'Kill the file
Kill fname
End Sub
It seems that sometimes it works(in debug mode) and sometimes it doesn't. If anyone has had this problem and has a fix could you let me know.
Thanks in advance.