Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Ed
 
Posts: n/a
Default Macro gives wrong table count?

I often do reports with lots of tables that get added, deleted and shuffled.
Tiring of going back through the document after each change to manually
renumber the tables, I created a macro to help me. (Unfortunately, due to
other considerations, the use of specific styles and fields aren't
possible.) The macro finds the selection point, sets a range to the
beginning of the document, and counts all the tables within the range. It
then adds one, puts it in the proper place, and we move on.

They made me use Track Changes on this round of reports, and I think it may
be messing with my macro. After successfully counting 35 tables, the next
one suddenly numbered 49!! I turned off Tracking and tried again, with the
same results. The macro is below. Any suggestions?

Ed

Sub CntTables()

Dim doc As Document
Dim rng1 As Range
Dim rng2 As Range

Set doc = ActiveDocument
' The table number placeholder is double-clicked
Set rng1 = Selection.Range
' Removing any trailing spaces from the range
Do While Right(rng1.Text, 1) = " "
rng1.MoveEnd wdCharacter, -1
Loop

Set rng2 = doc.Range(doc.Characters(1), rng1.End)
rng1.Text = rng2.Tables.Count + 1

End Sub


 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table in a Form HiDbLevel Tables 12 February 27th 06 12:59 PM
Select specific cells in table via macro Bill Sturdevant Microsoft Word Help 1 July 27th 05 03:01 PM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
Ideas for macro to add row for count and percentage Bradley C. Hammerstrom Tables 8 January 6th 05 10:38 AM
Word 2003 Table AutoFormat vs Macro vs VBA Kind writer/user/programmer Tables 1 October 28th 04 03:14 PM


All times are GMT +1. The time now is 04:43 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"