Can't create Excel.application

Discussion in 'AutoCAD' started by Matthew, May 25, 2004.

  1. Matthew

    Matthew Guest

    Is there a reason why I can't create an excel object on a couple of other
    pc's here in the office. Both of the pc's it will not work on have office
    2000 sr-1. I also have office 2000 sr-1 on my machine and it works on my pc.

    Function GetExcelOpen()
    Dim WKBobj As Workbook
    Dim WKSobj As Worksheet

    On Error Resume Next
    Err.Clear

    Set excelApp = GetObject(, "Excel.Application")
    ''' the line above fails on the other PC's
    If Err <> 0 Then
    Err.Clear
    Set excelApp = CreateObject("Excel.Application")
    If Err <> 0 Then MsgBox "Could not start Excel Application", vbExclamation
    End If
    excelApp.Visible = False
    Set WKBobj =
    excelApp.Workbooks.Open("C:/Standard/Cad/Shive/LayerImport/Layers.xls")
    End Function

    Any suggestions?
    Matthew
     
    Matthew, May 25, 2004
    #1
  2. Matthew

    Joe Sutphin Guest

    Do the other machines have other versions of Excel on them besides 2000? If
    this is the case then try the following modified code.

    Joe
    --
    Public Function GetExcelOpen() As Excel.Application

    On Error Resume Next

    Set GetExcelOpen = GetObject(, "Excel.Application.9")

    If Err Then
    Err.Clear

    Set GetExcelOpen = CreateObject("Excel.Application.9")

    If Err Then
    MsgBox "Could not start Excel Application", vbExclamation
    Exit Function
    End If
    End If
    End Function

    Public Sub Test()
    Dim oExcel As Excel.Application
    Dim WKBobj As Workbook
    Dim WKSobj As Worksheet

    Set oExcel = GetExcelOpen

    If Not oExcel Is Nothing Then
    oExcel.Visible = True
    MsgBox "Success"

    Else
    MsgBox "Failed"
    Exit Sub
    End If

    Set WKBobj =
    excelApp.Workbooks.Open("C:/Standard/Cad/Shive/LayerImport/Layers.xls")
    End Sub

    Sorry, I took the liberty of cleaning up a few things.
     
    Joe Sutphin, May 25, 2004
    #2
  3. Matthew

    Matthew Guest

    Joe, Thanks.

    I found a real nose bleed of a problem. error trapping is set differently
    on some machines for some goofy reason. When it is set to "Break on All
    Errors" it will give the error, but when it is set to "Break in Class
    module" or "Break on Unhandled Errors" there is no error message. Even on
    the code you posted there is still an error. How do make this work for the
    worst case scenario?

    Thanks for the help.
    Matthew
     
    Matthew, May 25, 2004
    #3
  4. Matthew

    Joe Sutphin Guest

    Personally, I set it to "Break on Unhandled Errors" and write error handling
    code.

    Joe
    --
     
    Joe Sutphin, May 26, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.