Sub ItaliciseVariable() ' Paul Beverley - Version 25.01.22 ' Runs along, finds sets of alpha chars and italicises them greekItalic = True ucaseGreekItalic = False avoidWords = ",to,and,or,at,sin,cos,tan" doTrack = False maxChars = 10 myTrack = ActiveDocument.TrackRevisions If doTrack = False Then ActiveDocument.TrackRevisions = False If Selection.Start = Selection.End Then Set rng = ActiveDocument.Content rng.Start = Selection.Start gotStart = False For i = 1 To Len(rng) myChar = rng.Characters(i) isText = (LCase(myChar) <> UCase(myChar)) If gotStart = False And isText Then Selection.Start = rng.Start + i - 1 gotStart = True End If If gotStart = True And isText = False Then Selection.End = rng.Start + i - 1 Exit For End If Next i If InStr(avoidWords, "," & Selection & ",") = 0 Then numChars = Len(Selection) myStart = Selection.Start Set rng = Selection.Range For i = 1 To numChars gotVar = False rng.End = myStart + i rng.Start = rng.End - 1 ch = rng.Text A = Asc(ch) u = AscW(ch) ' Ordinary letter If A = u Then gotVar = True If greekItalic = True Then If A = Asc("?") Then gotVar = True If u > 915 And u < 970 Then gotVar = True If ucaseGreekItalic = False And u < 945 Then gotVar = False End If If ucaseGreekItalic = False And u < -3999 Then gotVar = False End If If gotVar = True Then rng.Font.Italic = Not (isItalic) Else rng.Select Selection.Collapse wdCollapseEnd ActiveDocument.TrackRevisions = myTrack Exit Sub End If If i > maxChars Then Beep MsgBox "Stopped after " & Trim(Str(maxChars)) & " characters" ActiveDocument.TrackRevisions = myTrack Exit Sub End If Next i End If Selection.Collapse wdCollapseEnd Else If Selection <> " " Then Selection.Font.Italic = Not (Selection.Font.Italic) Selection.Collapse wdCollapseEnd End If ActiveDocument.TrackRevisions = myTrack End Sub