We help IT Professionals succeed at work.

Print any file type from VBA

I have a listbox with all the files in a directory.  These are mixed files types, workd, pdf, excel, etc.  Is there a way, when the user highlights the file name in the listbox and then hits print, to simply print the file without having to open it or use any type of object?  This is from an Access 2003 form in VBA.  The file types can also be 2003, 2007 or 2010 files.

Sandra
Comment
Watch Question

Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012
Commented:
try this.

Note that certain file won't just "print" using this.
It will depend on what application you have associated with the file extension

ex PDF's will sometimes keep the Adobe reader app open.

Basic code from here:
 http://www.mvps.org/access/api/api0018.htm
Access-EEQ27824846PrintFileFromV.mdb
MIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012
Commented:
If it were me, I would just open the folder in a web browser control.

Then you can print the file normally, (simply by right-clicking the file and selecting "Print")
This technique should always work.

Modified sample attached
Access-EEQ27824846PrintFileFromV.mdb
Sandra SmithRetired

Author

Commented:
Good information on both.  I finally told the user when they open the file, simply print from there.  Since they so rarely print I found out, this was the best way to solve the problem.

Sandra
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
OK,
Enjoy the weekend

Explore More ContentExplore courses, solutions, and other research materials related to this topic.