#1
|
|||
|
|||
VBA help with punctuation code
I first posted the issue in VBA Express several months ago but haven't had a reply to that so am posting here in the hope I can resolve some of the issues within the code. I hope I haven't broken any etiquette rules by doing so.
HTML Code:
http://www.vbaexpress.com/forum/showthread.php?69330-Word-VBA-help-with-missing-punctuation-macro&highlight= I need some help to iron out a few issues with the code. The code crashes when there are comments at the end of a paragraph with no punctuation. How can I tell the code to skip/ignore comments altogether. I have tried adding in Chr(160) to include if the semi-colon is followed by a non-breaking space instead of a space but it didn't work and now sure how to include for the code to look for both a space and/or a non-breaking space after a semi-colon. Code:
oRng.MoveStartWhile Chr(32), wdBackward Code:
Case "and", "but", "or", "then", "and/or", "plus", "minus", "less", "nor" Code:
Sub HighlightMissingPunctuation() Dim oPara As Paragraph Dim oRng As Range Application.ScreenUpdating = False On Error Resume Next For Each oPara In ActiveDocument.Paragraphs With oPara.Range Set oRng = oPara.Range oRng.End = oRng.End - 1 oRng.Collapse 0 oRng.MoveStartWhile Chr(32), wdBackward oRng.text = "" If .Characters.Last.Previous.InRange(ActiveDocument.TablesOfContents(1).Range) = False Then If oPara.Range.Information(wdWithInTable) = False Then If Len(.text) > 2 And Not .Font.Bold And Not .Font.AllCaps 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", "and/or", "plus", "minus", "less", "nor" Set oRng = .Words.Last.Previous.Words(1) oRng.MoveStartWhile Chr(32), wdBackward oRng.Start = oRng.Start - 1 If oRng.Characters(1) = ";" 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 End If If oRng.Characters(1) = "," Then 'if oPara ends with these words and have comma before them highlight pink .Words.Last.Previous.Words(1).HighlightColorIndex = wdPink End If Case Else End Select End If End With Next oPara Application.ScreenUpdating = True End Sub |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA Move Footnote References Before Punctuation | Shelley Lou | Word VBA | 28 | 09-22-2023 12:17 AM |
VBA code help: replacing punctuation | Shelley Lou | Word VBA | 8 | 07-01-2021 04:42 AM |
Excluding punctuation from tracked changes counts | jimmy12 | Word VBA | 0 | 06-23-2021 07:40 AM |
punctuation order | fariz | Word | 2 | 10-31-2016 12:57 AM |
Punctuation | lexsper | Word | 0 | 04-06-2015 07:26 AM |