Printing Excel File from Access VBA Hangs up Database

I have this code below that will open an excel file and then the print dialog box for the user to select the printer to print the excel file to. This code works fine on my computer but when my user tries to fire this code it freezes up the database and doesn't open the print dialog box. Any idea what would cause this to happen on another computer?

Sub PrintExcelFile()

    '1st ==> Set a Reference to the Microsoft Excel X.X Object Library
    Dim strPathToExcel As String, strSpreadsheetName As String
    Dim strWorksheetName As String
    Dim ExcelApp As New Excel.Application
    Dim ExcelBook As New Excel.Workbook
    Dim ExcelSheet As New Excel.Worksheet
    '******* Substitute your own values ********
    strPathToExcel = "\\SERVERPC\"
    strSpreadsheetName = "EIA template.xlsx"
    strWorksheetName = "Sheet1"
    'Let's not see what is going on
    ExcelApp.Visible = False
    Set ExcelBook = ExcelApp.Workbooks.Open(strPathToExcel & strSpreadsheetName)
    Set ExcelSheet = ExcelBook.Worksheets(strWorksheetName)
    ExcelBook.Close True
    Set ExcelApp = Nothing

End Sub

Open in new window

Lawrence SalvucciInformation Technology ManagerAsked:
Who is Participating?
ste5anSenior DeveloperCommented:
When it's the case, then yes. But it requires a lot of Win32 API stuff:

You need to find the window handle of that dialog and send a settopmost message to it.
Rory ArchibaldCommented:
Have you tried showing the Excel application before you show the dialog?
ste5anSenior DeveloperCommented:
Have you minimized all other windows? It seems that on some systems the dialog opens in the background.
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
No I didn't but I can see if that's the case. Is there a way to have it always move on top of other windows?
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
Ok Thanks. I'll do some research on the API to handle that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.