Excel File From Asp

S

Stan Sainte-Rose

Hi
I have to import Excel file from ASP.
I do it well with the following code
Const adUseClient = 3
Const adClipString = 2
Const Repertoire = "w:\wwwroot\look\j_consultation\j06_suivi\modules_stan\"
Set adoCn = CreateObject("ADODB.Connection")
Set adoRs = CreateObject("ADODB.Recordset")
With adoCn
..Provider = "Microsoft.Jet.OLEDB.4.0"
..ConnectionString = _
"Data Source=" & Repertoire & "Essai.xls;" & _
"Extended Properties=Excel 8.0;"
..CursorLocation = adUseClient
..Open
End With
strQuery = "SELECT * FROM [CONTROLE INTERNE$]"
With adoRs
Set .ActiveConnection = adoCn
..Open strQuery
End With


My question is how to get the Sheet Tab Name.
Right now, with my code I have to write [CONTROLE INTERNE$]
but how to do when you don't know the name ?

Thanks for your help

Stan
 
J

Jamie Collins

...
My question is how to get the Sheet Tab Name.
Right now, with my code I have to write [CONTROLE INTERNE$]
but how to do when you don't know the name ?

Use the Connection object's OpenSchema method e.g. (untested):

Const adUseClient = 3
Const adClipString = 2
Const Repertoire = "w:\wwwroot\look\j_consultation\j06_suivi\modules_stan\"
Const adSchemaTables = 20
Set adoCn = CreateObject("ADODB.Connection")
Set adoRs = CreateObject("ADODB.Recordset")
With adoCn
..Provider = "Microsoft.Jet.OLEDB.4.0"
..ConnectionString = _
"Data Source=" & Repertoire & "Essai.xls;" & _
"Extended Properties=Excel 8.0;"
..CursorLocation = adUseClient
..Open
Set adoRs = .OpenSchema(adSchemaTables)
End With
With adoRs
Do Until .EOF
MsgBox !TABLE_NAME
.MoveNext
Loop
End With

--
 
R

Radovan Vojtek

Hi Jamie!

Are you sure with the exlamation (!) ?

Microsoft VBScript compilation error '800a03ea'
Syntax error
/test.asp, line 19
MsgBox !TABLE_NAME
-------^

I'd like to solve it, but I'm an ASP (and VBScript) newbie :)

Thanx

--
R.V.


Jamie Collins said:
...
My question is how to get the Sheet Tab Name.
Right now, with my code I have to write [CONTROLE INTERNE$]
but how to do when you don't know the name ?

Use the Connection object's OpenSchema method e.g. (untested):

Const adUseClient = 3
Const adClipString = 2
Const Repertoire = "w:\wwwroot\look\j_consultation\j06_suivi\modules_stan\"
Const adSchemaTables = 20
Set adoCn = CreateObject("ADODB.Connection")
Set adoRs = CreateObject("ADODB.Recordset")
With adoCn
..Provider = "Microsoft.Jet.OLEDB.4.0"
..ConnectionString = _
"Data Source=" & Repertoire & "Essai.xls;" & _
"Extended Properties=Excel 8.0;"
..CursorLocation = adUseClient
..Open
Set adoRs = .OpenSchema(adSchemaTables)
End With
With adoRs
Do Until .EOF
MsgBox !TABLE_NAME
.MoveNext
Loop
End With
 
J

Jamie Collins

...
Hi Jamie!

Are you sure with the exlamation (!) ?

Microsoft VBScript compilation error '800a03ea'
Syntax error
/test.asp, line 19
MsgBox !TABLE_NAME
-------^

Yes, but only within the With clause i.e. could be rewritten as

MsgBox adoRs!TABLE_NAME

or

MsgBox adoRs.Fields("TABLE_NAME").Value

Jamie.

--
 
R

Radovan Vojtek

Thanx, Jamie, it works!!! godlike

R.V.

Jamie Collins said:
...


Yes, but only within the With clause i.e. could be rewritten as

MsgBox adoRs!TABLE_NAME

or

MsgBox adoRs.Fields("TABLE_NAME").Value

Jamie.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top