Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2005, 11:08 AM
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using ADO to query data in Excel sheet Fails with

excel ADO Extended Parameter Passing Fails with Spaces in http path.

ConnectionString = _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & ThisWorkbook.FullName & ";" & _
    "Extended Properties=Excel 8.0;"

The file is located at:

http:\\folder\folder%20again\filename.xsl

 
Old June 9th, 2005, 11:55 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sub myXLRecordSet()
Dim myADOConn As ADODB.Connection
Dim myADORs As ADODB.Recordset
Dim mySQL As String
Dim myConn As String

Line10:
    Set myADOConn = New ADODB.Connection
    Set myADORs = New ADODB.Recordset
    myConn = "DSN=Excel Files;" & _
        "DBQ=C:\sampledata.xls;" & _
        "DefaultDir=C:;" & _
        "DriverId=790;MaxBufferSize=2048;PageTimeout=5 ;"
Line20:
    mySQL = "SELECT T1.*"
    mySQL = mySQL & " FROM myDBase T1"

Line30:
    myADOConn.Open myConn
    myADORs.Open Source:=mySQL, ActiveConnection:=myADOConn

    If Not (myADORs.BOF Or myADORs.EOF) Then
        myADORs.MoveFirst

        Do While Not myADORs.EOF
            ActiveCell.Offset(0, 0).Value = myADORs.Fields(0).Value
            ActiveCell.Offset(0, 1).Value = myADORs.Fields(1).Value
            myADORs.MoveNext
            ActiveCell.Offset(1, 0).Select
        Loop
        myADORs.Close
        myADOConn.Close
    Else
        MsgBox ("No Records to Display, please drink some Cocoa")
    End If

Application.ScreenUpdating = True


    Set myADORs = Nothing
    Set myADOConn = Nothing
End Sub


 
Old June 9th, 2005, 12:07 PM
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I understand the concept of pulling and incerting data via ADO, the problem is that in the MS SharePoint environment the "Data Source=" & ThisWorkbook.FullName & ";" & _ part of the ADO fails when it trys to pass the http:\\ with spaces. It remoces the %20 and leaves the space.

Example:
http:\\something%20Something\filename.xls


 
Old June 9th, 2005, 12:29 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure if this will work, but try putting this bit of code in first,

myDSource = ThisWorkbook.FullName
myDSource = Replace(myDSource, "%20", Chr$(37) & "20")
ConnectionString = _
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & myDSource & ";" & _
    "Extended Properties=Excel 8.0;"

What results do you get?

Matt

 
Old June 9th, 2005, 01:56 PM
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get this error. "Invalid Internet Address" when the connectionstring is passing."http://teamsites.fm.ith.xxxx.com/sites/SOX_Prog_Mgmt/Mgmt%20Reports/Q2/STestOX_2005_indicators_data.xls"

SQL = "SELECT COUNT(*) FROM [TestingDetail$]" & _
        "WHERE TestStatus = 'Complete' AND DocTitle IS NOT NULL AND ProcBusCycl = 'COS'"
        Set cRecordset = New ADODB.Recordset
        On Error GoTo Cleanup
        Call cRecordset.Open(SQL, ConnectionString, _
        CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly, _
        CommandTypeEnum.adCmdText)
   Call Sheets("Indicators").Range("E4").CopyFromRecordset (cRecordset)







Similar Threads
Thread Thread Starter Forum Replies Last Post
Export data from a datalist to an Excel sheet see07 ASP.NET 1.x and 2.0 Application Design 3 February 23rd, 2007 07:20 PM
Exporting data to excel sheet x_ray VB.NET 2002/2003 Basics 0 January 6th, 2006 03:14 PM
reading data from excel sheet rajiv_software Classic ASP Basics 2 April 30th, 2005 01:03 AM
Query data and exporting data from one sheet to an testman Excel VBA 2 April 28th, 2005 02:40 PM
Exporting data from a repeater to an Excel sheet see07 ASP.NET 1.x and 2.0 Application Design 7 January 17th, 2005 03:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.