Results 1 to 12 of 12

Thread: VBA Control - Table/Grid

  1. #1

    Thread Starter
    Banned
    Join Date
    Aug 2006
    Posts
    77

    VBA Control - Table/Grid

    I need to display information read from a database in a table in a VBA userform (MS Excel). I am aware of MSFlexGrid, and have tried to use it, but I have ran into a brickwall due to its well documented limitations. The following are the features I need from the table/grid control:

    -row-based event detection (mouseover, mouse clicks, etc)
    -ability to choose between, on a per-column basis:
    Automatic resizing of column-widths if text in a row is too long
    OR
    Text wrapping if string in a row is too long for a defined column-width
    -Column sort
    -Automatic vertical scrollbar if number of rows is large
    -Ability to have hidden columns
    -Freeware!

    Are there any controls that exist out there that have all of these abilities? Do you have any other solutions for displaying data in a grid in a VBA userform? Thanks for your help.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VBA Control - Table/Grid

    Excel VBA question moved to Office Development

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

    Re: VBA Control - Table/Grid

    One neat trick is to use an "Microsoft Office Spreadsheet xx.0" control.

    Gives you everythiing that the Excel Sheet does but placed on a UserForm.
    Attached Images Attached Images  
    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

  4. #4
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: VBA Control - Table/Grid

    Be careful with the Spreadsheet control, it doesn't support ALL excel's objects, methods, collections, and properties.

    For example, today I was helping someone with this object. They wanted to use AutoFilter and automatically filter a specific item, but the Spreadsheet control doesn't support "Criteria1, Field, Criteria2, etc" for Autofilter. I did manage to find a workaround, after some digging.

    Incase you have a question about that, check out:

    http://www.vbaexpress.com/forum/showthread.php?t=9940

    And I also couldn't set a Range variable to the range on the Spreadsheet control, which was weird...I kept getting a type mismatch error.
    Last edited by malik641; Oct 23rd, 2006 at 11:03 PM.




    If you find any of my posts of good help, please rate it

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

    Re: VBA Control - Table/Grid

    Just dim your Range variable as an Object.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub UserForm_Click()
    4.     Dim oRange As Object
    5.     Set oRange = Spreadsheet1.Range(Spreadsheet1.Cells(1, 1), Spreadsheet1.Cells(1, 2))
    6.     MsgBox oRange.Address '"$A$1:$B$1"
    7. End Sub
    8.  
    9. Private Sub UserForm_Initialize()
    10.     Spreadsheet1.Cells(1, 1) = "Meow!"
    11.     Spreadsheet1.Cells(1, 2) = "Meow!"
    12. End Sub
    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

  6. #6
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: VBA Control - Table/Grid

    Quote Originally Posted by RobDog888
    Just dim your Range variable as an Object.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub UserForm_Click()
    4.     Dim oRange As Object
    5.     Set oRange = Spreadsheet1.Range(Spreadsheet1.Cells(1, 1), Spreadsheet1.Cells(1, 2))
    6.     MsgBox oRange.Address '"$A$1:$B$1"
    7. End Sub
    8.  
    9. Private Sub UserForm_Initialize()
    10.     Spreadsheet1.Cells(1, 1) = "Meow!"
    11.     Spreadsheet1.Cells(1, 2) = "Meow!"
    12. End Sub
    Hmmm...so is it were as if I'm connecting to excel using late binding?




    If you find any of my posts of good help, please rate it

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

    Re: VBA Control - Table/Grid

    It appears to be the case but I really think it may be that the control uses a slightly different "Range" object with the same or similar props, methods, and functions etc. So the types may not be 100% equilivalent and cause the early binding type mismatch error.

    I just use early binding to get my code in place and take advantage of the intellisense and then switch it to late binding and Im good to go.
    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

  8. #8
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: VBA Control - Table/Grid

    Quote Originally Posted by RobDog888
    It appears to be the case but I really think it may be that the control uses a slightly different "Range" object with the same or similar props, methods, and functions etc. So the types may not be 100% equilivalent and cause the early binding type mismatch error..
    I see...do you think it has anything to do with the fact that it's the Web Components object model and not Excel?

    Quote Originally Posted by RobDog888
    I just use early binding to get my code in place and take advantage of the intellisense and then switch it to late binding and Im good to go.
    Even if your code's written in VBA? (I can understand automating, say, access from excel...but I meant automating excel from within excel).




    If you find any of my posts of good help, please rate it

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

    Re: VBA Control - Table/Grid

    It could be as the object type may be named differently or just different enough to not match.


    Yes, I meant Excel VBA inside of Excel VBA for just the code concerning the UserForm with the web control on it.
    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

  10. #10
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: VBA Control - Table/Grid

    Quote Originally Posted by RobDog88
    Yes, I meant Excel VBA inside of Excel VBA for just the code concerning the UserForm with the web control on it.
    ....for the web components you still get the intellisense even without the reference. The intellisense treats it (Spreadsheet object) as if it's a worksheet object...




    If you find any of my posts of good help, please rate it

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

    Re: VBA Control - Table/Grid

    Yes, but if you declare an object variable of Range and then try to set the range to a range on the web control you get the type mismatch erro like we been over. SoI was meaning that when writting the code that is directly related to the web control I do this but never removing any references as thats not needed.



    VB Code:
    1. Dim oRange As [b]Excel.Range[/b]
    2.     Set oRange = Spreadsheet1.Range(Spreadsheet1.Cells(1, 1), Spreadsheet1.Cells(1, 2))
    3.     MsgBox oRange.Address '"$A$1:$B$1"
    VB Code:
    1. Dim oRange As Object
    2. Set oRange = Spreadsheet1.Range(Spreadsheet1.Cells(1, 1), Spreadsheet1.Cells(1, 2))
    3.     MsgBox oRange.[b]Address[/b] '"$A$1:$B$1"
    Where .Address is not displayed when using late binding to get around the type error. So I use this first and then switch it over.
    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

  12. #12
    Addicted Member malik641's Avatar
    Join Date
    Sep 2005
    Location
    South Florida :-)
    Posts
    221

    Re: VBA Control - Table/Grid

    Ok, I gotcha. Thanks RobDog888




    If you find any of my posts of good help, please rate it

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