#1
|
|||
|
|||
VBA IF Statement Help
I have created a macro to help me when formatting documents. The code finds instances of rogue punctuation, mostly ones that are bold and highlights them bright green so I can easily identify what I need to reformat in line with housestyle. I've got the code to also not highlight bold punctuation if contained within a bold heading or part of a bold definition through the IF Statement.
I'm struggling of what to add to the IF Statement to capture other instances e.g. more than one bold punctuation together (see 1.8 of the attached document where I've listed a few examples). Would appreciate any advice. Bold Punc but not within Bold Text.docx Code:
Sub HighlightBoldPuncDemo1() Application.ScreenUpdating = False Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Highlight = True 'Activate replacement highlighting .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True Options.DefaultHighlightColorIndex = wdBrightGreen .text = Chr(34) 'Highlight non-bold straight quotes .Font.Bold = False .Execute Replace:=wdReplaceAll .text = "[[\]^0145^0146^0147^0148]{1,}" 'Highlight non bold curly quotes/apostrophes/square brackets .Execute Replace:=wdReplaceAll .text = "[" & Chr(44) & Chr(145) & Chr(146) & Chr(147) & Chr(148) & "\(\)\[\]\:\;\.\'\,]" 'Highlight bold curly quotes/apostrophes, brackets/square brackets, comma etc. .Font.Bold = True .Execute Replace:=wdReplaceAll End With With oRng.Find .text = "[" & Chr(34) & "\(\)\[\]\:\;\.\'\,]" 'highlight bold straight quotes if word is plain text but don't highlight if all bold .Font.Bold = True While .Execute oRng.Select On Error Resume Next If oRng.Characters.Last.Next.Font.Bold = False Then oRng.HighlightColorIndex = wdBrightGreen 'highlight if bold but not within a heading or definition If oRng.Characters.Last.Previous.Font.Bold = True Then oRng.HighlightColorIndex = wdNoHighlight 'don't highlight if contained within a bold heading Wend End With End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
IF Statement (again) | 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 |
Need a little help with an if statement | cangelis | Excel | 2 | 04-08-2015 05:55 PM |
If statement, may be? | Tony Singh | Excel | 6 | 03-04-2015 12:52 PM |
Need help with If, Then Statement Please | cangelis | Excel | 4 | 01-03-2014 09:10 AM |