printing powerpoint in access 2003 using VBA

Hi experts,

I would like to print a powerpoint presentation, excel file and a pdf file direct to the printer using a command button on a form.  I have been able to do this for Word, but not for any of these.

Can anybody offer assistance?

Many thanks,
Terry


TerenceHewettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rockiroadsCommented:
Have u looked into ShellExecute? That has the ability to print files

rockiroadsCommented:
eg,

post this code into a Module


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

Private Declare Function ShellExecuteForExplore Lib "shell32.dll" Alias "ShellExecuteA" _
  (ByVal hWnd As Long, ByVal lpOperation As String, _
  ByVal lpFile As String, lpParameters As Any, _
  lpDirectory As Any, ByVal nShowCmd As Long) As Long

Public Enum EShellShowConstants
    essSW_HIDE = 0
    essSW_MAXIMIZE = 3
    essSW_MINIMIZE = 6
    essSW_SHOWMAXIMIZED = 3
    essSW_SHOWMINIMIZED = 2
    essSW_SHOWNORMAL = 1
    essSW_SHOWNOACTIVATE = 4
    essSW_SHOWNA = 8
    essSW_SHOWMINNOACTIVE = 7
    essSW_SHOWDEFAULT = 10
    essSW_RESTORE = 9
    essSW_SHOW = 5
End Enum

Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&
Private Const SE_ERR_ACCESSDENIED = 5        ' access denied
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_FNF = 2                ' file not found
Private Const SE_ERR_NOASSOC = 31
Private Const SE_ERR_PNF = 3                ' path not found
Private Const SE_ERR_OOM = 8                ' out of memory
Private Const SE_ERR_SHARE = 26


Public Function RunApp(ByVal sFile As String, _
                       Optional ByVal eShowCmd As EShellShowConstants = essSW_SHOWDEFAULT, _
                       Optional ByVal sParameters As String = "", _
                       Optional ByVal sDefaultDir As String = "", _
                       Optional sOperation As String = "open", _
                       Optional Owner As Long = 0) As Boolean
    Dim lR As Long
    Dim lErr As Long, sErr As Long
   
    If (InStr(UCase$(sFile), ".EXE") <> 0) Then
        eShowCmd = 0
    End If
   
    On Error Resume Next
    If (sParameters = "") And (sDefaultDir = "") Then
        lR = ShellExecuteForExplore(Owner, sOperation, sFile, 0, 0, essSW_SHOWNORMAL)
    Else
        lR = ShellExecute(Owner, sOperation, sFile, sParameters, sDefaultDir, eShowCmd)
    End If
   
    If (lR < 0) Or (lR > 32) Then
        RunApp = True
    Else
        ' raise an appropriate error:
        lErr = vbObjectError + 1048 + lR
        Select Case lR
            Case 0
            lErr = 7: sErr = "Out of memory"
            Case ERROR_FILE_NOT_FOUND
                lErr = 53: sErr = "File not found"
            Case ERROR_PATH_NOT_FOUND
                lErr = 76: sErr = "Path not found"
            Case ERROR_BAD_FORMAT
                sErr = "The executable file is invalid or corrupt"
            Case SE_ERR_ACCESSDENIED
                lErr = 75: sErr = "Path/file access error"
            Case SE_ERR_ASSOCINCOMPLETE
                sErr = "This file type does not have a valid file association."
            Case SE_ERR_DDEBUSY
                lErr = 285: sErr = "The file could not be opened because the target application is busy. Please try again in a moment."
            Case SE_ERR_DDEFAIL
                lErr = 285: sErr = "The file could not be opened because the DDE transaction failed. Please try again in a moment."
            Case SE_ERR_DDETIMEOUT
                lErr = 286: sErr = "The file could not be opened due to time out. Please try again in a moment."
            Case SE_ERR_DLLNOTFOUND
                lErr = 48: sErr = "The specified dynamic-link library was not found."
            Case SE_ERR_FNF
                lErr = 53: sErr = "File not found"
            Case SE_ERR_NOASSOC
                sErr = "No application is associated with this file type."
            Case SE_ERR_OOM
                lErr = 7: sErr = "Out of memory"
            Case SE_ERR_PNF
                lErr = 76: sErr = "Path not found"
            Case SE_ERR_SHARE
                lErr = 75: sErr = "A sharing violation occurred."
            Case Else
                sErr = "An error occurred occurred whilst trying to open or print the selected file."
        End Select
   
        Err.Raise lErr, , Application.hWndAccessApp & ".GShell", sErr
        RunApp = False
    End If
   
End Function





Now if u wanted to print a file, u can simply do this

'Pass in name of doc, then in the action (default is open), specify Print
RunApp "c:\ee\testdoc2.doc", , , , "print"

options available are those available in the registry (i.e.right click on a file in windows explorer)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TerenceHewettAuthor Commented:
Rocki - you rock!!  Thank you so much for this code, it has worked brilliantly. Just wondered though, with Word, Excel and PP when the file prints it opens up the file, prints and then closes.  With the PDF the code opens up the file and prints, which is great, but it leaves the reader application open.  Can this be closed in the same way as Word for example?

I will award the points anyway as you have been terrific but would quite like the PDF app to close after printing. If this is a separate question, let me know and I will post into a new question.

Cheers and thank you again.

Terry
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

rockiroadsCommented:
When u right click in explorer on a PDF and select Print, what does it do?
The code basically emulates what would happen in Explorer

Only way I could think of is if we sent a close signal to that
TerenceHewettAuthor Commented:
Rocki,  I felt like I was asking too much for one post, so have reposted as a new question.  I like the idea you have of sending a close signal, so if you can help me with that, I would be very much appreciated.  The new post is at:

http://www.experts-exchange.com/Databases/MS_Access/Q_21982425.html

Best regards and thanks again.
Terry
rockiroadsCommented:
ok, I found the api

PostMessage

but u need to handle of the window. Im not sure if FindWindow api call does that.
I will investigate
rockiroadsCommented:
Nice of you to open another question, I would of answered here anyway, so appreciate how you appreciate the experts :)
rockiroadsCommented:
or rather I appreciate!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.