Macro that inserts automatic numbering fields in a table

L

LizW

Our office often has to number the leftmost column in a
table. If we do it manually, and then insert and delete
rows, we have to renumber everything from scratch. I'd
like to create a macro that will insert the Autolglnum
field (because it updates on insert or delete rows) and
continue to loop until it reaches the end of the table. It
could be 66 rows or 157 rows - so I can't use For, or
Repeat commands if I have to specify a number each time.

So far I have this:

Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \* Arabic \e ",
PreserveFormatting:=False
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \* Arabic \e ",
PreserveFormatting:=False

This puts in the number 1 in the first row, goes down, and
inserts the number 2 in the next row. However I would then
like it to repeat and look until the cursor comes to the
end of the table. I don't know how to Repeat the Actions
that came before and also, I'm not sure how to
specify "the end of the table" in VBA.

Any ideas? Thanks!
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Liz,

If you select the column and then click on the numbering button on the
toolbar, each cell in the column will be numbered in a way that when you add
or delete a row, the numbering us automatically adjusted.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top