Subject: probleme with CreateObject(“Excel.Application”)
Amad,
I think you need to look in the registry to get the full object name for the latest install of excel - you will find something like “HKEY_CLASSES_ROOT\Excel.Application.11”
I have found that you then need to use that full value in the create object as follows:
Set XLApp=CreateObject(“Excel.Application.11”)
If this works, you must consider your full user base as they might have a varied install of Excel and so require different values.
This could be acheived by having an onError handler for err 208 (I think that’s the one).
within the err handler you could then change the value to the previous release and try to create the object and so on …
take a look at some example code that I have used …
Hope that helps … John Kvalheim
Dim versionflag As String
versionflag = “11”
GetOrCreate = “Get”
…
On Error 209 Goto AppNotOpen’ Ensure that we don’t open Excel if it’s already open
On Error 208 Goto Previousversion’ Ensure that we try with other version
…
'Launch Excel
launcher:
If versionflag = "11" Then
appname = "Excel.Application.11"
Else
appname = "Excel.Application.10"
End If
If GetOrCreate = "Get" Then
Set XApp = GetObject(appname)
Else
Set XApp = CreateObject(appname)
End If
…
AppNotOpen:
' error code 209
'if Excel is not already open an expected error occurs
GetOrCreate = "Create"
Resume Launcher
…
Previousversion:
' error code 208
versionflag = "10"
If getOrCreate = "Get" Then
GetOrCreate = "Create"
Else
GetOrCreate = "Get"
End If
Resume Launcher