[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

bart.smissaert@gmail.com

11/5/2011 4:02:00 PM

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.

RBS

4 Answers

Mike Williams

11/5/2011 4:50:00 PM

0

"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


bart.smissaert@gmail.com

11/5/2011 7:33:00 PM

0

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
>
>

Dee Earley

11/7/2011 10:54:00 AM

0

On 05/11/2011 19:32, RB Smissaert wrote:
> 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.

ShellExecute with the "print" verb will work for any file type that the
handling application says it supports printing for.
It is entirely down to that application whether it gives a print dialog,
automatically uses a specific or the default printer and whether it's
visible or not.

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

DaveO

11/7/2011 12:01:00 PM

0


"RB Smissaert" <bart.smissaert@gmail.com> wrote in message
news:j9430m$pmo$1@dont-email.me...
> 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

It could be argued that in this context picture files are "document files"
as a document file is one that can be opened, displayed, manuipulated,
stored and printed by at least one program and is not necessarily just text.

DaveO.