PrintingHTML




'If MSHTML.DLL Is installed In the system directory, you can

'use the following code :

Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias
"GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STATUS_PENDING = &H103&
Public Sub PrintHtmlFile(cHtmlFile As String)
Dim hProcess As Long
Dim ProcessId As Long
Dim ExitCode As Long
Dim cWinSysDir As String
cWinSysDir = String(254, " ")
Call GetSystemDirectory(cWinSysDir, Len(cWinSysDir))
cWinSysDir = Trim(Left(cWinSysDir, InStr(cWinSysDir, Chr(0)) - 1))
If Dir(cWinSysDir & "\MSHTML.DLL") <> "" Then
ProcessId = Shell("rundll32.exe " & cWinSysDir &
"\MSHTML.DLL,PrintHTML " & Chr(34) & cHtmlFile & Chr(34), vbNormalFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While ExitCode = STATUS_PENDING
Call CloseHandle(hProcess)
End If
End Sub

'If MSHTML.DLL Is installed In the system directory, you can use the

'following code :

Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias
"GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STATUS_PENDING = &H103&
Public Sub PrintHtmlFile(cHtmlFile As String)
Dim hProcess As Long
Dim ProcessId As Long
Dim ExitCode As Long
Dim cWinSysDir As String
cWinSysDir = String(254, " ")
Call GetSystemDirectory(cWinSysDir, Len(cWinSysDir))
cWinSysDir = Trim(Left(cWinSysDir, InStr(cWinSysDir, Chr(0)) - 1))
If Dir(cWinSysDir & "\MSHTML.DLL") <> "" Then
ProcessId = Shell("rundll32.exe " & cWinSysDir &
"\MSHTML.DLL,PrintHTML " & Chr(34) & cHtmlFile & Chr(34), vbNormalFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While ExitCode = STATUS_PENDING
Call CloseHandle(hProcess)
End If
End Sub











( printinghtml.html )- by Paolo Puglisi - Modifica del 17/12/2023