In the function below, I try to use the API ShellExecuteEx to print documents stored on disk drives. The documents can be Word, Excel, Visio, etc. This routine is supposed to automatically print the documents, no matter the format and application, and on my computer it does. However, on other computers, it may not. On some of the computers we are using, when a Visio document is opened, a print dialog box displays (with correct printer) and the user is obligated to click on the OK icon to print. In one case a word document just opened without doing anything else, forcing the user to do the print manually. And I periodically get printing to a device that is not my default printer.
The only other piece is that, prior to printing, a change the default printer to one that prepares a postscript file. This is done using the WriteProfileString API, along with Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows") to send message to existing open windows.
The systems involved are either Windows XP Professional or Windows 2000.
The code I use is:
Private objDocument As Object, lpt1 As Printer, dummy
Private gdbCurrent As Database, strTempFile As String
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
Declare Function ShellExecuteEx Lib "shell32.dll" Alias _
"ShellExecuteExA" (shxInfo As SHELLEXECUTEINFO) As Long
Public Function ConvertDocumentToPDF(strFullPath As String) As Long
Dim llngRetCode As Long, ldatStart As Date, lpdfDist As PdfDistiller6
Dim lshexInfo As SHELLEXECUTEINFO, exitCode As Long, hProcess As Long
AddStack "ConvertDocumentToPDF(" & strFullPath & ")"
On Error GoTo ErrConvertDocumentToPDF
.cbSize = Len(lshexInfo)
.fMask = SEE_MASK_NOCLOSEPROCESS
.hwnd = hWndAccessApp
.lpVerb = "PRINT"
.lpFile = strFullPath
.lpParameters = vbNullString
.lpDirectory = gstrWorkingDir
.nShow = SW_HIDE
llngRetCode = ShellExecuteEx(lshexInfo)
ConvertDocumentToPDF = PrintToPDF(llngRetCode)
ConvertDocumentToPDF = False
I would appreciate any help you can provide.