|
-
Nov 29th, 2005, 06:56 AM
#1
Thread Starter
New Member
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?
-
Nov 29th, 2005, 08:44 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 2nd, 2005, 06:25 AM
#3
Re: Dyanamic Table Word
 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:
Function fnCreateTbl(NumberOfRows As Integer, NumberOfColumns As Integer, _
Optional blnTblBorders As Boolean = False)
'This function will create a table.
Application.ScreenUpdating = False
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=NumberOfRows, _
NumColumns:=NumberOfColumns, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitWindow
'To remove borders
Selection.Tables(1).Borders.Enable = blnTblBorders
Application.ScreenUpdating = True
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|