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)
     
    ExcelApp.Dialogs(8).Show
    ExcelBook.Close True
    ExcelApp.Quit
    Set ExcelApp = Nothing


End Sub

Open in new window

LVL 1
Lawrence SalvucciInformation Technology ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Rory ArchibaldCommented:
Have you tried showing the Excel application before you show the dialog?
0
ste5anSenior DeveloperCommented:
Have you minimized all other windows? It seems that on some systems the dialog opens in the background.
0
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?
0
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.
0

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
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
Ok Thanks. I'll do some research on the API to handle that.
0
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.