Adding Tables to Word

JuliaReynolds
JuliaReynolds used Ask the Experts™
on
I am trying to get tables to add into a word document and do not know how to do it, I have pasted the information below and attached the word document so that you can see the actual tables.  

I  need to create two macros and/or non- printing command buttons, one to add  new topic title tables

(This is the Topic Title Table)  each time a new topic title is added it would need to appear on the next blank page.  A page break would need to be written in the command
2.      Click here to enter Topic Title

and one that would add the section title table (this table’s numbering convention would need to follow that of the topic title section above it (ie when topic title table:2 is added all section tables inserted beneath it would follow the 2.1, 2.2, 2.3 etc  numbering and when topic title table 3 is added the sections tables beneath it would follow the 3.1, 3.2, 3.3 etc. numbering convention. (there is a potential for several section title tables to be under each topic title table).

2.1      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      
(this is the Section Title Table)

When a new Topic title table is added it needs to start on the next available page number.  A simple page break in the code should work


On my template I am going to have the topic title and one section on it.

2.      Click here to enter Topic Title
2.1      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      



Below is what an example of what I am trying to accomplish, this is the topic title table added and 5 section title tables added followed by another topic title table with three title tables added.

2.      Click here to enter Topic Title
2.1      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      
2.2      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      
2.3      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      
2.4      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      
2.5      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      



3      Click here to enter Topic Title
3.1      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      
3.2      "[Click here to enter Section Title]"

      
      "[Click here to enter Section Text]"

      
3.3      "[Click here to enter Section Title]"

      



I was also hoping to get the topic titles, section number and associated page numbers to auto insert to a table of contents on the first page of the document, is that possible?

Topic      Page
2.      Click here to enter topic title.
Pg Number.

3.      Click here to enter topic title
Pg Number.

4.      Click here to enter topic title
Pg Number



The table on the front would have to add a row if additional Topic Title sections were added.
Inserting-Tables-into-Word-Help-Needed.d
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
What version of office are you using

Author

Commented:
2010
Retired
Top Expert 2012
Commented:
Your question is more of a project specification than a single question.

To add a table, you need some code like this:
Sub Newtable()
    Dim MyTable As Table
    
    Set MyTable = AddATable(ActiveDocument, ActiveDocument.Bookmarks("\EndOfDoc").Range, 6, 3)
End Sub
Function AddATable(doc As Document, rng As Range, iRows As Integer, iCols As Integer) As Table
    Set AddATable = doc.Tables.Add(rng, iRows, iCols)
End Function

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
How would you get the table to add once you have written the code

Commented:
Julia, you would need to add the code then run the code. As per Graham's comment the scope of this question is a little broad... Graham has given you 2 approaches for adding tables, you can call the sub by typing NewTable in the VBA IDE Immediate window.
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial