Shell Print Any Document
Easy code allows you to print any document on the computer using its default print handler. This is the same as if you right-click in the windows explorer and select Print. No command switches are needed. So simple I added a handy ShellExecute Error Handler.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Public Function ShellPrint(jFormHwnd As Long, FilePath As String) As String
Dim Answer As Integer
Dim Msg As String
Answer = ShellExecute(jFormHwnd, "Print", FilePath, vbNullString, vbNullString, vbNormalFocus)
If Answer <= 32 Then
'There was an error
Select Case Answer
Case SE_ERR_FNF
Msg = "File not found"
Case SE_ERR_PNF
Msg = "Path not found"
Case SE_ERR_ACCESSDENIED
Msg = "Access denied"
Case SE_ERR_OOM
Msg = "Out of memory"
Case SE_ERR_DLLNOTFOUND
Msg = "DLL not found"
Case SE_ERR_SHARE
Msg = "A sharing violation occurred"
Case SE_ERR_ASSOCINCOMPLETE
Msg = "Incomplete or invalid file association"
Case SE_ERR_DDETIMEOUT
Msg = "DDE Time out"
Case SE_ERR_DDEFAIL
Msg = "DDE transaction failed"
Case SE_ERR_DDEBUSY
Msg = "DDE busy"
Case SE_ERR_NOASSOC
Msg = "No association for file extension"
Case ERROR_BAD_FORMAT
Msg = "Invalid EXE file or error in EXE image"
Case Else
Msg = "Unknown error"
End Select
End If
ShellPrint = Msg
End Function
Private Sub Command1_Click()
Dim x As String
x = ShellPrint(Me.hwnd, "C:\Bad File")
If x <> vbNullString Then
MsgBox x
End If
End Sub
Original Comments (3)
Recovered from Wayback Machine