Print any file type from VBA

Posted on 2012-08-10
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
    LVL 74

    Assisted Solution

    by:Jeffrey Coachman
    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

    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

    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
    Enjoy the weekend

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This collection of functions covers all the normal rounding methods of just about any numeric value.
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now