![]() |
#6
|
|||
|
|||
![]()
Shelley,
If you pull that loop out and run it on your test document, you will see where and why the error occurs: Code:
Sub A() Dim oPara As Paragraph Dim Rng As Range On Error GoTo Err_Handler: For Each oPara In ActiveDocument.Paragraphs 'Highlights missing punctuation at end of paragraphs With oPara.Range If .Information(wdWithInTable) Or .Font.AllCaps Or .Characters.First.Font.Bold Or Len(.Text) < 3 Then GoTo NextFor Else If Not .Characters.Last.Previous Like "*[.!?:;,]" Then If Not .Characters.Last.Previous.Fields(1).Result = "]" Then If Not .Characters.Last.Previous Like "]" Then .Words.Last.Previous.Words(1).HighlightColorIndex = wdPink End If End If End If Select Case .Words.Last.Previous.Words(1) Case "and", "but", "or", "then", "plus", "minus", "less", "nor" Set Rng = .Words.Last '.Previous.Words(1) Rng.MoveStartUntil cSet:=" " & Chr(160), Count:=-10 Set Rng = Rng.Characters.First.Previous.Previous If Rng.Text = ";" Then 'if oPara ends with these words and have semi-colon before them do nothing no highlight else .Words.Last.Previous.Words(1).HighlightColorIndex = wdNoHighlight If Rng.Text = "," Then 'if oPara ends with these words and have semi-colon before them do nothing no highlight else .Words.Last.Previous.Words(1).HighlightColorIndex = wdPink End If End If Case Else End Select End If End With NextFor: Next lbl_Exit: Exit Sub Err_Handler: MsgBox Err.Number & " - " & Err.Description oPara.Range.Select Resume End Sub There is no field(1) in the range. |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
teza2k06 | Excel | 8 | 02-11-2022 08:41 AM |
Converting a Select statement in Excel to an update statement | shabbaranks | Excel Programming | 5 | 10-31-2018 11:47 PM |
![]() |
cangelis | Excel | 2 | 04-08-2015 05:55 PM |
![]() |
Tony Singh | Excel | 6 | 03-04-2015 12:52 PM |
![]() |
cangelis | Excel | 4 | 01-03-2014 09:10 AM |