![]() |
|
|
Thread Tools | Display Modes |
#10
|
||||
|
||||
![]()
It matters because your code will then skip over tables with merged cells - that's the whole point of implementing the test that way, as per your request in post #5.
Try: Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long, StrTxt As String, Tbl As Table For Each Tbl In ActiveDocument.Tables With Tbl For i = .Range.Cells(.Range.Cells.Count).RowIndex To 2 Step -1 ' Counts the rows by 1 down On Error Resume Next If .Rows(i - 1).Cells.Count > 1 Then ' Rows will count by one cell If InStr(.Cell(i, 2).Range.Text, "Ensure S") = 1 Then ' if the second column starts with "Ensure S" you know what I mean the first part of the procedure in the step then StrTxt = Split(.Cell(i, 2).Range.Text, " ")(1) ' Until the End or until the space is found after "Ensure S" .Rows.Add BeforeRow:=.Rows(i) ' Add an extra row for the Grey Bar With .Rows(i) .Cells.Merge 'Merge those Cells! .Shading.BackgroundPatternColor = -603930625 'Grey those cells! .Range.Style = wdStyleNormal 'wdStyleNormal is the normal font template, for me which is Times new roman 12 for others it could be arial or calabri based on the template .Range.ParagraphFormat.KeepWithNext = wdToggle 'Keep with next .Range.Text = "Step " & StrTxt 'add "Step" Text infront of the step number .Range.Rows.Height = 18 'Height is configurable .Range.Bold = wdToggle 'Bold the Grey Bar text .Range.Font.Size = 10 'Now shrink the text End With End If Else i = i - 1 ' Makes the program not crash <- Suprisingly the hardest part lol End If Next End With Next Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
ksigcajun | Word VBA | 24 | 02-16-2023 03:09 PM |
![]() |
VBLearner | Word VBA | 1 | 03-09-2014 08:42 PM |
VBA sort table code | mikec | Excel Programming | 8 | 10-01-2013 04:37 PM |
![]() |
donbexcel | Word VBA | 1 | 11-02-2011 05:25 AM |
how can I add a peace of code to MS document | amlife | Word VBA | 0 | 03-03-2010 03:35 PM |