Results 1 to 31 of 31

Thread: [RESOLVED]Using Ado To Access Excel Files

Hybrid View

  1. #1
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Using Ado To Access Excel Files

    Your still not opening a ADODB connection and placing the reverse single quote around the sheet name.
    VB Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim sPath As String
    4.     Dim oRs as ADODB.Recordset
    5.  
    6.     sPath = App.Path & "\TestFile.xls"
    7.    
    8.     Set oRs = GetADOExcelRecordSet(sPath)
    9.    
    10. End Sub
    11.  
    12.  
    13. Private Function GetADOExcelRecordSet(ByVal Path As String, _
    14.                 Optional ByVal Headers As Boolean = True) As Recordset
    15.                
    16.     Dim sCnn As String
    17.     Dim sWorksheet As String
    18.     Dim sRequest As String
    19.    
    20.     sWorksheet = "Sheet1"
    21.    
    22.     Dim oCnn As ADODB.Connection
    23.     Set oCnn = New ADODB.Connection
    24.     Dim oRs As Recordset
    25.     Set oRs = New ADODB.Recordset
    26.    
    27.     sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    28.             "Data Source=" & Path & ";" & _
    29.             "Extended Properties=""Excel 8.0;HDR=No" & _
    30.             IIf(Headers, "Yes", "No") & """"
    31.            
    32.     oCnn.ConnectionString = sCnn
    33.     oCnn.Open
    34.  
    35.     'Read a sheet:
    36.  
    37.     sRequest = "SELECT * FROM [`" & sWorksheet & "$`]"
    38.     oRs.Open sRequest, oCnn, adOpenDynamic, adLockOptimistic
    39.     Set GetADOExcelConnection = oRs
    40.    
    41. End Function
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Using Ado To Access Excel Files

    Dave's conversion service.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width