Probleme with CreateObject("Excel.Application")

I have a problem with the importation from Excel and more precisely in the creation of the object

Set XLApp=CreateObject(“Excel.Application”)

can be because I use Excel 2003 which has to change repertoire and thus the object cannot be built I don’t know??!!! can be it is that!!

what I must do

thanks

Subject: What error are you getting? (WAS: probleme with CreateObject(“Excel.Application”))

It could be down to the object name changing with Excel 2003, yes (see my post here about that). What error do you get?

Subject: probleme with CreateObject(“Excel.Application”)

Excel can’t handle more than 1 hadle to the application.

Try this, it works fine for me in Excel 2003.

Print “Connecting to Excel…”

bObjectCreated = False

On Error Resume Next

Set excel = GetObject(“”, “Excel.Application”)

If excel Is Nothing Then

Set excel = CreateObject("Excel.Application")

bObjectCreated = True

End If

On Error Goto whateverlabelyouhave…

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