Results 1 to 11 of 11

Thread: Collapsible Microsoft word tables

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    4

    Collapsible Microsoft word tables

    Hello. I am new here and was referred from another site.
    I wanted to know if there was a way to make Collapsible Tables in a Microsoft Word program

    i.e. Say I wanted to make a table containing 5 columns and endless rows. Is there a way I could then collapse that table while I work on a new table.

    It sounds like it should be a practical thing to do, but I am not sure..

    Please Help

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Collapsible Microsoft word tables

    you could save the table data into an array (or for safety an external file) then delete the table, insert the table back later
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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

    Re: Collapsible Microsoft word tables

    Welcome to the Forums.

    Yes its possible and an interesting idea.

    I'm about done with it so I'll post up a FAQ and link it here for you in a few minutes
    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

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    4

    Re: Collapsible Microsoft word tables

    Quote Originally Posted by RobDog888
    Welcome to the Forums.

    Yes its possible and an interesting idea.

    I'm about done with it so I'll post up a FAQ and link it here for you in a few minutes


    Oh ok thank you very much... I wasn't sure that was something that could be done. But I guess with the right coding, anything is possible.

    Allowing for collapsible tables would be beneficial as it would allow one to work on several tables without having to clog up the whole screen...

    Please let me know if something that could be done.. I would appreciate it very much.

    This forum seems to be filled with Geniuses... I am glad I found it. I have to come in here more often..

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

    Re: Collapsible Microsoft word tables

    I got it working last night but didnt have enough time to clean it up. Its on my system at home so when I get home I will clean it up a bit and post 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

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    4

    Re: Collapsible Microsoft word tables

    Quote Originally Posted by RobDog888
    I got it working last night but didnt have enough time to clean it up. Its on my system at home so when I get home I will clean it up a bit and post it.
    Thank you very much. I look forward to seeing how it all works out.

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    4

    Re: Collapsible Microsoft word tables

    Hey RobDog888. Any luck at all? Were you able to come up with something?

  8. #8
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: Collapsible Microsoft word tables

    It certainly is an interesting idea. I hadn't thought of it before, but it's certainly workable. I wonder how performance would work on larger tables. You could also use hidden fonts to just hide/unhide the table, but that can be thwarted by that pesky show hidden characters button. Then again, Word isn't really a presentation software package so there will always be something that can mess things up with work-arounds.

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Collapsible Microsoft word tables

    I made this simple macro if this suits your needs.

    Just copy & paste this macro in your VBA editor. You may assign it to a toolbar button or keyboard shortcut for ease of use.
    Then keep the cursor on any cell in the table you want to expand/collapse and run this macro.

    vb Code:
    1. Sub ToggleCollapseTable()
    2.     Dim tbl As Table
    3.     Dim newState As Boolean
    4.     Set tbl = Selection.Tables(1)
    5.     If tbl Is Nothing Then Exit Sub     'if selection is not a table
    6.     If tbl.Rows.Count < 2 Then Exit Sub 'if table can't be expanded/collapsed
    7.     newState = Not tbl.Rows(2).Range.Font.Hidden
    8.     For i = 2 To tbl.Rows.Count
    9.         tbl.Rows(i).Range.Font.Hidden = newState
    10.     Next
    11. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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

    Re: Collapsible Microsoft word tables

    Finally done with xmas and stuff.

    I finished it the other day but have been away til now. I used the .SetHeight method of the rows to epand and collapse tables. Since in 2007 its alot harder to ass a custom button I used an ActiveX button from the designer and added it to the first row of the table where the table header row is.

    Nice code Pradeep

    I posted mine on another vb office forum site and can PM you the link (not sure if its cool to post the link) if you want as I'm not sure I will post it in my FAQ here yet. Pradeeps code will do the job on pre-2007 Word.
    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

  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Collapsible Microsoft word tables

    This one is faster than the one I posted earlier and has the same effect, since it doesn't have to loop through the table rows:

    vb Code:
    1. Sub ToggleCollapseTable()
    2.     Dim tbl As Table, rng As Range
    3.     Dim newState As Boolean
    4.     Set tbl = Selection.Tables(1)
    5.     If tbl Is Nothing Then Exit Sub     'if selection is not a table
    6.     If tbl.Rows.Count < 2 Then Exit Sub 'if table can't be expanded/collapsed
    7.     Set rng = tbl.Rows(2).Range
    8.     newState = Not rng.Font.Hidden
    9.     rng.MoveEnd Unit:=wdTable, Count:=1
    10.     rng.Font.Hidden = newState
    11. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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