-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCondenseAll.vba
49 lines (41 loc) · 1.71 KB
/
CondenseAll.vba
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
Function isTextParagraph(p As Paragraph) As Boolean
If p.outlineLevel = wdOutlineLevelBodyText And InStr(p.Range.Words(1).Style, "Style 13 pt Bold,Cite") = 0 Then
'Example style string is: "Style 13 pt Bold,Cite,Style Style Bold + 12 pt,Style Style Bold,Style Style Bold + 12pt,Style Style + 12 pt,Style Style Bo... +,Old Cite,Style Style Bold + 10 pt,tagld + 12 pt,Style Style Bold + 13 pt,Style Style Bold + 11 pt"'
isTextParagraph = True
Exit Function
End If
isTextParagraph = False
End Function
Sub CondenseAll()
Dim p As Paragraph
Dim doc As Document
Dim rngDoc As Range
Set doc = ActiveDocument
Dim firstTextParagraph As Paragraph
Dim lastTextParagraph As Paragraph
Set firstTextParagraph = Nothing
Set lastTextParagraph = Nothing
For Each p In ActiveDocument.Paragraphs
If isTextParagraph(p) Then
If firstTextParagraph Is Nothing Then
Set firstTextParagraph = p
End If
Set lastTextParagraph = p
Else
If Not firstTextParagraph Is Nothing Then
Set rngDoc = doc.Range(Start:=firstTextParagraph.Range.Start, End:=lastTextParagraph.Range.End)
rngDoc.Select
Formatting.Condense
Set firstTextParagraph = Nothing
Set lastTextParagraph = Nothing
End If
End If
Next p
If Not firstTextParagraph Is Nothing Then
Set rngDoc = doc.Range(Start:=firstTextParagraph.Range.Start, End:=lastTextParagraph.Range.End)
rngDoc.Select
Formatting.Condense
Set firstTextParagraph = Nothing
Set lastTextParagraph = Nothing
End If
End Sub