Results 1 to 3 of 3

Thread: Dyanamic Table Word

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    4

    Dyanamic Table Word

    I can create a dynamic table using (ActiveDocument.Tables.Add) etc... but it creates a fixed number of rows. I want to load a .txt file in Word with 5 rows of data and then populate a table. There could be a hundred rows and will be different every time. Can anyone help?

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

    Re: Dyanamic Table Word

    If you record a macro of you creating a table then your generated code will show you how to create it with whatever rows or columns you need.
    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
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Dyanamic Table Word

    Quote Originally Posted by smittyb
    I can create a dynamic table using (ActiveDocument.Tables.Add) etc... but it creates a fixed number of rows. I want to load a .txt file in Word with 5 rows of data and then populate a table. There could be a hundred rows and will be different every time. Can anyone help?
    First you need to read the text file and count how many no. of paragraphs are there in the text file, then only you can specify that in the create table function.
    VB Code:
    1. Function fnCreateTbl(NumberOfRows As Integer, NumberOfColumns As Integer, _
    2.                      Optional blnTblBorders As Boolean = False)
    3.     'This function will create a table.
    4.     Application.ScreenUpdating = False
    5.     ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=NumberOfRows, _
    6.                               NumColumns:=NumberOfColumns, _
    7.                               DefaultTableBehavior:=wdWord9TableBehavior, _
    8.                               AutoFitBehavior:=wdAutoFitWindow
    9.     'To remove borders
    10.     Selection.Tables(1).Borders.Enable = blnTblBorders
    11.     Application.ScreenUpdating = True
    12. End Function
    In the above function you need to enter the number of rows and columns for your table.
    ______________________
    CS.

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