Results 1 to 3 of 3

Thread: Using ADO to access a closed Excel Spreadsheet

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158

    Question Using ADO to access a closed Excel Spreadsheet

    I've been doing searches for awhile, and getting mostly examples like this one:
    http://www.exceltip.com/st/Use_a_clo...Excel/432.html
    I'm not good with SQL and was hoping to find something simple so I could finish what I'm doing quickly.

    I need to connect to a workbook/sheet without opening it and find the last used row(If Cell(1,1) is empty, it will be a blank row). Then on the next row down I need to copy some text into a few columns worth of cells.

    If I have to use SQL, I guess I could use some pointers. I learned a tiny bit of it once to get through another project but it gave me a headache and I stink at it

    Oh and I'm actually using 97-VBA if that limits me at all.

    Thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    This willl return the last row with data in it.
    VB Code:
    1. MaxRowNumber = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
    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

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is one of my functions that I wrote with ADO to connect to an
    excel spreadsheet.
    CnnE = ADO Public connection.
    frmMain.lblPath = path/filename to the spreadsheet - can be hard coded.
    Function returns true when the connection is made.
    VB Code:
    1. Public Function ExcelConnect() As Boolean
    2. '<RR 03/17/03>
    3.     On Error GoTo No_Bugs
    4.  
    5.     If CnnE.State = adStateClosed Then
    6.         CnnE.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; DATA Source=" & frmMain.lblPath & ";Extended Properties=Excel 8.0;"
    7.         CnnE.CursorLocation = adUseClient
    8.         CnnE.Open
    9.         ExcelConnect = True
    10.     Else
    11.         CnnE.Close
    12.         CnnE.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; DATA Source=" & frmMain.lblPath & ";Extended Properties=Excel 8.0;"
    13.         CnnE.CursorLocation = adUseClient
    14.         CnnE.Open
    15.         ExcelConnect = True
    16.     End If
    17.     Exit Function
    18.    
    19. No_Bugs:
    20.    
    21.     ExcelConnect = False
    22.  
    23. 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

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