Con la chiamata ad una funzione API.
Puoi usare ShellExecute passando la stringa di PRINT
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
Private Const SW_SHOWNORMAL = 1
ShellExecute hWnd, "PRINT", "C:\NomeFile.Doc", vbNullString, vbNullString, SW_SHOWNORMAL
La questione dell'Handle dipende da come lo gestisci... se hai una Form di chiamata usi quello altrimenti usi l'hWnd di defualt che è [0].
Alternativa c'è ShellExecuteEx, ma devi passare una variabile strutturata...
Private Declare Function ShellExecuteEx Lib "shell32.dll" _
(SEI As SHELLEXECUTEINFO) As Long
Const SEE_MASK_INVOKEIDLIST = &HC
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SEE_MASK_FLAG_NO_UI = &H400
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
End Type
Sub PrintFile(FileName As String, OwnerhWnd As Long)
Dim SEI As SHELLEXECUTEINFO
Dim r As Long
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or _
SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
.hwnd = OwnerhWnd
.lpVerb = "print"
.lpFile = FileName
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
r = ShellExecuteEx(SEI)
End Sub
chiaramente la chiamata è questa
Private Sub Pulsante3_Clic()
Dim strFile As String
strFile = "C:\NomeFile.Doc"
PrintFile strFile , Me.hwnd
End Sub
Chiaramente per sistemi Operativi 64Bit serve la modifica della dichiarazione API.