#1
|
|||
|
|||
Dynamic table numbers
Hello VBA Specialists,
I want a help to write a macro which find all the tables in document and adds numbers in incremental order. The example table is Table.JPG There are many tables in the document and all tables don't have same number of steps. Could anyone please help me to write the macro. Thanks a lot. With regards, Srinidhi |
#2
|
||||
|
||||
Provided the tables are in the body of the document and not in headers footers, text boxes etc, and are similar to that shown, then the following should work.
Code:
Sub NumberTables() Dim oTable As Table Dim i As Long, j As Long Dim oCell As Range i = 1 For Each oTable In ActiveDocument.Tables For j = 2 To oTable.Rows.Count Set oCell = oTable.Cell(j, 1).Range oCell.End = oCell.End - 1 oCell.Text = i & Chr(46) 'This is what goes in the cells! i = i + 1 Next j Next oTable lbl_Exit: Set oTable = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
It works partly, but the table numbers are incrementing and for each table I might need the numbering to start from the beginning. I will try to find out what could be done. If i am not, then please help me.
Thanks a lot With regards, Srinidhi |
#4
|
||||
|
||||
If you want the numbers to restart for each table, move the line
Code:
i = 1 Code:
For Each oTable In ActiveDocument.Tables
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Solved. Thanks a lot
|
#6
|
|||
|
|||
Hi,
To the same issue, how could the not set all tables in ActiveDocument.Tables but tables from page 2 to end. Because this macro is changing my title page, as there is a table which is generated automatically from the template file. Thanks a lot. With regards, Srinidhi |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Dynamic Mail Merged Table | hanskimber | Mail Merge | 2 | 04-24-2015 11:21 PM |
Add content to Dynamic/Automatic Table of Contents | rosenina18 | Word | 3 | 04-14-2015 05:15 AM |
Dynamic Pivot Table in 2013 | Alaska1 | Excel | 0 | 01-29-2015 10:33 AM |
Mail Merge Into Dynamic Table | Jag618 | Mail Merge | 1 | 03-04-2013 11:26 PM |
VBA: Include Dynamic Sheet Name In Pivot Table Source Data | ibrahimaa | Excel Programming | 2 | 04-28-2012 12:27 AM |