Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2019, 12:28 PM
gmaxey gmaxey is offline Design macro insert number table rows Windows 10 Design macro insert number table rows Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim oRng As Range
Dim strList As String
Dim oRow As Row
Dim lngRow As Long
  For Each oTbl In ActiveDocument.Tables
    If oTbl.Style = "Protix Table" Then
      Set oRng = oTbl.Range
      oRng.Collapse wdCollapseStart
      oRng.Move wdParagraph, -1
      If Not oRng.Paragraphs(1).OutlineLevel < 10 Then
        Do
          oRng.Move wdParagraph, -1
        Loop Until oRng.Paragraphs(1).OutlineLevel < 10
      End If
    End If
    strList = oRng.Paragraphs(1).Range.ListFormat.ListString
    lngRow = 0
    For Each oRow In oTbl.Rows
      If oRow.Index > 1 Then
        lngRow = lngRow + 1
        oRow.Cells(1).Range.Text = strList & "." & lngRow
      End If
    Next oRow
  Next oTbl
lbl_Exit:
  Exit Sub
End Sub

__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 09-20-2019, 12:05 AM
simons simons is offline Design macro insert number table rows Windows 10 Design macro insert number table rows Office 2019
Novice
Design macro insert number table rows
 
Join Date: Sep 2019
Posts: 4
simons is on a distinguished road
Default

It works up until I have other tables in the document aswell
If there is another table style used before the 'protix table' then it doesn't work
If there is another table style used after a 'protix table' then it also gives that table an ID number.
Attached Files
File Type: docx Table ID test.docx (15.2 KB, 6 views)
Reply With Quote
Reply

Tags
insert number



Similar Threads
Thread Thread Starter Forum Replies Last Post
Design macro insert number table rows Design Macro or Code to Delete Table Rows When Null/Blank/Empty Upon Doc Close/Save aaghd72 Word VBA 8 02-18-2019 11:22 AM
How to find number of coma and then add that number of rows in word using macro? PRA007 Word VBA 7 05-27-2015 10:45 PM
Creating a table for a variable number of rows OllieOnline Mail Merge 1 03-27-2013 02:48 PM
Using macro to add variable number of rows to a protected word table Julia Word Tables 1 01-09-2013 06:04 AM
Design macro insert number table rows Fixing number or rows in a table burnsie Word 2 07-12-2011 02:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:20 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft