bart.smissaert@gmail.com
11/5/2011 7:33:00 PM
Thanks for that.
I did have a look at ShellExecute, but it looked it only
dealt with document files, not for example image files.
Will try your code and let you know.
RBS
"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:j93pe6$oql$1@dont-email.me...
> "RB Smissaert" <bart.smissaert@gmail.com> wrote in message
> news:j93mm7$6g6$1@dont-email.me...
>> Is there a way to print any file in VB6 or VBA, ideally with the
>> default application?
>> I am mainly dealing with Word .doc files and image files, but there also
>> can be other files that can only be opened in meaningful way by their
>> default, specialised application. I suppose there is no other way then
>> looking at the file type and use different methods for the different
>> files, but thought it worth asking if there is some kind of generic way.
>
> There might be better ways of doing it but ShellExecute might suit your
> needs. The following should print whatever file you have, although this
> simple example causes the Shelled application to show briefly while it is
> dealing with printing the document and, never having used ShellExecute in
> earnest myself, I do not offhand know how to prevent that and how to make
> it so that the application performs its task invisibly in the background.
>
> Mike
>
> 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
> Const SW_SHOWNORMAL = 1
> Private Const SW_HIDE = 0
> Private Const SWP_HIDEWINDOW = &H80
> Private Const SW_MINIMIZE = 6
> Private Const SW_SHOWMINIMIZED = 2
>
> Private Sub Command1_Click()
> ShellExecute Me.hwnd, "print", "C:\temp\readme.docx", "", "", SW_HIDE
> End Sub
>
>