I have a project that I export from MadCap Flare into Word 2010 and I use a VBA script to update the formatting of the document. I am trying to check the style of every paragraph in the document, then if it matches a specific style apply a multi list level format.
It almost works problem-free. The problem arises when the paragraph falls as the last paragraph in a table cell. In this case, the range includes the end of cell marker (so the range includes every paragraph of the cell) and thus the change applies to every paragraph in the table cell instead of simply the last.
The code I use is as follows:
For Each iPara In ActiveDocument.Paragraphs
With iPara.Range
If iPara.Style.NameLocal = "div_NoteText" Then
.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdOutlineNumberGallery).ListTemplates(1), _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList, _
DefaultListBehavior:=wdWord10ListBehavior, ApplyLevel:=1
End If
End With
Next
What changes do I need to make for this to work for the last paragraph in a table cell?
The "end of cell" marker is Chr(13) + Chr(7), so you can detect a paragraph located at the end of a cell using code similar to below:
Sub Tester()
Dim EOC As String
Dim p As Paragraph
Dim rng As Range
EOC = Chr(13) & Chr(7)
For Each p In ActiveDocument.Paragraphs
If Len(p.Range.Text) > Len(EOC) And p.Range.Text Like "*" & EOC Then
Set rng = p.Range
'commenting out next line will select the whole cell
rng.MoveEnd wdCharacter, -1
rng.Select
MsgBox "Found paragraph at end of cell..."
End If
Next p
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With