Results 1 to 4 of 4

Thread: How to go about in Importing Excel data into a grid?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    19

    How to go about in Importing Excel data into a grid?

    Good afternoon

    I would like to import data from an Excel file and fill a grid with the data. Any ideas on how to do it?
    I would also like to import text from an external source, something like a txt file and import it in to a grid.

    eg If I was to copy 20 rows of text, from either an excel file or a txt file and copy it into a grid. Is there a way for the data to be placed into the grid?

    I am a novice at Vb6 so any help will be much appreciated. Thank you.

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

    Re: How to go about in Importing Excel data into a grid?

    Welcome to the Forums.

    One way would be to have a loop that went through the used range in Excel and place each value in the grid.


    VB Code:
    1. Dim oApp as excel.application
    2. dim oWB as excel.workbook
    3. dim iRow as integer
    4. dim iCol as integer
    5.  
    6. set oapp = new excel.application
    7. set owb = oapp.workbooks.open("C:\Book1.xls")
    8.  
    9. irow = owb.cells.range.specialcells(xlCellTypeLastCell).Row
    10. icol = owb.cells.range.specialcells(xlCellTypeLastCell).Column
    11.  
    12. 'Todo: loop though the row/columns adding the cells(irow, icol).Value to each cell in your grid.
    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

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    19

    Resolved Re: How to go about in Importing Excel data into a grid?

    G'day RobDog888.

    That makes alot of sense, I havent tried it but it looks like it should work. Brilliant!!

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

    Re: How to go about in Importing Excel data into a grid?

    Thanks, there are a couple of other more complex methods that may be better if your coping allot of records.

    Post back if you have any problems with this.
    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