forked from OHI-Science/ohimanual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docx_fixes.vbscript
62 lines (49 loc) · 1.23 KB
/
docx_fixes.vbscript
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
Sub ohimanual_fixes()
'
' ohimanual_fixes Macro
' From: https://github.com/bbest/dissertation#word-tweaks
'
'
'----
' resize figures
Dim shp As Word.Shape
Dim ishp As Word.InlineShape
Dim width_in As Integer
width_in = 6
' iterate over all shapes
For Each shp In ActiveDocument.Shapes
shp.LockAspectRatio = True
shp.Width = InchesToPoints(width_in)
Next
' iterate over all inline shapes
For Each ishp In ActiveDocument.InlineShapes
ishp.LockAspectRatio = True
ishp.Width = InchesToPoints(width_in)
Next
'----
' add table of contents after 1st paragraph
Dim toc_str As String
Dim rng As Object
toc_str = "Table of Contents"
' set location in doc
Set rng = ActiveDocument.Range( _
Start:=ActiveDocument.Paragraphs(1).Range.End, _
End:=ActiveDocument.Paragraphs(1).Range.End)
' add toc
ActiveDocument.TablesOfContents.Add rng, _
UseFields:=True, _
UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1
' prefix toc with string
With ActiveDocument.Paragraphs(1).Range
.InsertParagraphAfter
.InsertAfter (toc_str)
.InsertParagraphAfter
End With
' make toc bold
With Selection.Find
.Replacement.Font.Bold = True
.Execute FindText:=toc_str, replaceWith:=toc_str
End With
End Sub