Link to home
Start Free TrialLog in
Avatar of Lawrence Salvucci
Lawrence SalvucciFlag for United States of America

asked on

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

Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you tried showing the Excel application before you show the dialog?
Have you minimized all other windows? It seems that on some systems the dialog opens in the background.
Avatar of Lawrence Salvucci

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok Thanks. I'll do some research on the API to handle that.