PC Review


Reply
Thread Tools Rate Thread

ADO access to excel workbook on website

 
 
Dreiding
Guest
Posts: n/a
 
      4th Dec 2008
I have Excel 2003 and trying to use ADO to read data from an excel file
stored in a website folder without success.

The code below shows two definition of the "SourceFile". The second one
works.
When I use the first one the 'rsCon.Open szConnect' code fails.

Any thoughts, suggestion to make this work?

My code:

Option Explicit

Sub GetData()
Dim rsCon As Object
Dim rsData As Object
Dim szConnect As String
Dim szSQL As String

Dim SourceFile As String

SourceFile = "http://MyComputer.us.pat.com/iisfolder/My_Lookup_Table.xls"
SourceFile = "\\MyComputer.us.pat.com\iisfolder\My_Lookup_Table.xls"

'Create connection string
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & SourceFile & ";" & _
"Extended Properties=""Excel 8.0;HDR=No"";"
'sql query
szSQL = "SELECT * FROM [Sheet1$A2:A2];"

On Error GoTo Err_GetData

Set rsCon = CreateObject("ADODB.Connection")
Set rsData = CreateObject("ADODB.Recordset")

rsCon.Open szConnect
rsData.Open szSQL, rsCon, 0, 1, 1

' Check to make sure we received data and copy the data
If Not rsData.EOF Then
MsgBox rsData.fields(0).Value
End If

' Clean up our Recordset object.
rsData.Close
rsCon.Close

Set rsData = Nothing
Set rsCon = Nothing
Exit Sub

Err_GetData:
MsgBox "The file name, Sheet name or Range is invalid of: " &
SourceFile, vbExclamation, "Error"
On Error GoTo 0
End Sub

Thanks,
- Pat
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      4th Dec 2008
I don't think ADO will let you connect over HTTP.

Tim

"Dreiding" <(E-Mail Removed)> wrote in message
news:33CDCA15-4613-454E-860B-(E-Mail Removed)...
>I have Excel 2003 and trying to use ADO to read data from an excel file
> stored in a website folder without success.
>
> The code below shows two definition of the "SourceFile". The second one
> works.
> When I use the first one the 'rsCon.Open szConnect' code fails.
>
> Any thoughts, suggestion to make this work?
>
> My code:
>
> Option Explicit
>
> Sub GetData()
> Dim rsCon As Object
> Dim rsData As Object
> Dim szConnect As String
> Dim szSQL As String
>
> Dim SourceFile As String
>
> SourceFile = "http://MyComputer.us.pat.com/iisfolder/My_Lookup_Table.xls"
> SourceFile = "\\MyComputer.us.pat.com\iisfolder\My_Lookup_Table.xls"
>
> 'Create connection string
> szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=" & SourceFile & ";" & _
> "Extended Properties=""Excel 8.0;HDR=No"";"
> 'sql query
> szSQL = "SELECT * FROM [Sheet1$A2:A2];"
>
> On Error GoTo Err_GetData
>
> Set rsCon = CreateObject("ADODB.Connection")
> Set rsData = CreateObject("ADODB.Recordset")
>
> rsCon.Open szConnect
> rsData.Open szSQL, rsCon, 0, 1, 1
>
> ' Check to make sure we received data and copy the data
> If Not rsData.EOF Then
> MsgBox rsData.fields(0).Value
> End If
>
> ' Clean up our Recordset object.
> rsData.Close
> rsCon.Close
>
> Set rsData = Nothing
> Set rsCon = Nothing
> Exit Sub
>
> Err_GetData:
> MsgBox "The file name, Sheet name or Range is invalid of: " &
> SourceFile, vbExclamation, "Error"
> On Error GoTo 0
> End Sub
>
> Thanks,
> - Pat



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 workbook not linking properly with authentic website Mr. Larson Microsoft Excel Misc 0 5th Jun 2008 03:15 AM
Export Excel Workbook to a Website scott56hannah Microsoft Excel Programming 0 31st Mar 2008 04:31 AM
access a website from excel 2003 spreadsheet =?Utf-8?B?UmljYXJkbw==?= Microsoft Excel New Users 0 25th Oct 2006 11:31 PM
publishing semi-PROTECTED excel workbook as a dynamic website =?Utf-8?B?VGhhbmsgeW91?= Microsoft Excel Programming 0 25th Sep 2006 06:01 AM
link Access workbook to Excel workbook =?Utf-8?B?VG9pbmV0dA==?= Microsoft Excel Misc 1 31st Jan 2005 03:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.