View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ivan F Moala[_3_] Ivan F Moala[_3_] is offline
external usenet poster
 
Posts: 38
Default Print Command on a file

"Spencer Hutton" wrote in message ...
is there a way to execute the print command on a file from excel. liek if
you were to right click on a file and choose print from the shortcut menu.


To simulate this then amend this to your needs
This prints a word Doc....

Option Explicit

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_HIDE = 0
Private Const strFilePath As String = "C:\White Rose\Templates\WRS
Compliments Slips.doc"

Sub WordPrint()
Dim retVal As Long

retVal = ShellExecute(0, "Print", strFilePath, 0, 0, SW_HIDE)

If retVal < 32 Then
'// there are Error codes for this..left out
MsgBox "An Error occured...could not print"
End If

End Sub