Print any file type from VBA

Posted on 2012-08-10
Medium Priority
Last Modified: 2012-08-10
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.

Question by:ssmith94015
  • 3
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 2000 total points
ID: 38281334
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:
LVL 74

Accepted Solution

Jeffrey Coachman earned 2000 total points
ID: 38281367
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

Author Closing Comment

ID: 38281480
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.

LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38281533
Enjoy the weekend

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
When we develop an application in Ms Access 2016 we should also try to protect the queries, macros and table links. I know I may not have a permanent solution but for novice users, they will not manage to break your application. Below is the detail …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question