-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConvertEntireBoldLess.txt
62 lines (51 loc) · 2.08 KB
/
ConvertEntireBoldLess.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Private Sub SpeedReaderFullDocRoundDown()
'Follow me on IG @GPFSye
' Ctrl + G opens the console log so you can track progress
' On larger documents, this will freeze, but don't worry, the code is solid, VBA is just slow, it'll take awhile
' but it'll get there lol
Application.ScreenUpdating = False
Dim i, c As Long
Dim objRegex As RegExp
Dim matches As MatchCollection
Dim fnd As Match
Dim Coll As New Collection
Set objRegex = New RegExp
Set myRange = ActiveDocument.Content
' Great excuse to play with regex
With objRegex
.Pattern = "\b(?:[A-Za-z]{1}(?=[A-Za-z]{0}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{2}(?=[A-Za-z]{1}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{3}(?=[A-Za-z]{2}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{4}(?=[A-Za-z]{3}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{5}(?=[A-Za-z]{4}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{6}(?=[A-Za-z]{5}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{7}(?=[A-Za-z]{6}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{8}(?=[A-Za-z]{7}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{9}(?=[A-Za-z]{8}[A-Za-z]?[A-Za-z]\b)|[A-Za-z]{10}(?=[A-Za-z]{9}[A-Za-z]?[A-Za-z]\b))"
.Global = True
.IgnoreCase = True
Set matches = .Execute(myRange)
End With
For Each fnd In matches
On Error Resume Next
Coll.Add fnd, fnd
On Error GoTo 0
Next fnd
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Font.Bold = True
.Format = True
.Forward = True
.Wrap = wdFindStop
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchPrefix = True
For Each fnd In Coll
On Error Resume Next
Debug.Print fnd & " " & c & "/" & Coll.Count
c = c + 1
.Text = fnd
.Replacement.Text = "^&"
.Execute Replace:=wdReplaceAll
On Error GoTo 0
Next fnd
End With
myRange.ParagraphFormat.LineSpacing = LinesToPoints(2)
Application.ScreenUpdating = True
End Sub