-
Notifications
You must be signed in to change notification settings - Fork 0
/
EbookMacros.bas
1510 lines (1395 loc) · 48.2 KB
/
EbookMacros.bas
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "Module1"
Const commonWordFileName As String = "ebookfindreplace.txt"
Const commonWordWildcardFileName As String = "ebookwildcardreplace.txt"
Sub FixEmDashes()
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = " - ([!^013-]{3,170})-([,."" ])"
.replacement.text = " ^+\1^+\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = " -([!^013-]{3,200})-([^013,. ])"
.replacement.text = " ^+\1^+\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = " —([,."" ])"
.replacement.text = "—\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub FindNextCutoffParagraph()
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find.Font
.Bold = False
End With
With Selection.Find
.text = "([!0-9.""" & ChrW(8221) & _
"^013^058…^t\?'\!\)\(^175^148^02])[^013]{1,2}([A-Za-z])"
.replacement.text = "\1 \2"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
End Sub
Sub FindNextHardHyphenatedWord()
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "([a-z])- ([a-z])"
.replacement.text = "\1\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
End Sub
Sub WhatChrIsThis()
MsgBox "Ascii code #" & Asc(Selection.Range.text)
End Sub
Sub ChangeAllAllCapsToSentenceCase()
Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
.Wrap = wdFindContinue
.Forward = True
.Format = False
.MatchWildcards = True
.text = "[A-Z]{2}[A-Z ]{1,254}"
.replacement.text = ""
.Execute
While .Found
If Not IsCapRomanNumeral(Selection.Range.text) Then
Debug.Print "Setting """ & Selection.text & """ to sentence case."
Selection.Range.Case = wdTitleWord
End If
Selection.Collapse Direction:=wdCollapseEnd
.Execute
Wend
End With
End Sub
Function IsCapRomanNumeral(text As String) As Boolean
Dim length As Integer
Dim theChar As Integer
length = Len(text)
IsCapRomanNumeral = True
For i = 1 To length
theChar = Asc(Mid(text, i, 1))
'I, V, X, L, M, <space>
If theChar <> 86 And theChar <> 88 And theChar <> 73 And _
theChar <> 76 And theChar <> 77 And theChar <> 32 Then
IsCapRomanNumeral = False
Exit Function
End If
Next
End Function
Sub FixCapitalizedMonthsInSpanish()
Dim months As Variant
months = Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", _
"Octubre", "Noviembre", "Diciembre")
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
For i = 0 To 11
Selection.HomeKey Unit:=wdStory
With Selection.Find
.text = "([!.^058\?""""'\!\)\(^175^148^013^09]) " & months(i)
.replacement.text = "\1 " & LCase(months(i))
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
Sub LoadAndExecuteFileReplacements()
'strings to search:
Dim findBin(255) As String
Dim replaceBin(255) As String
Dim replaceCount As Integer
Dim fileNum As Integer
Dim dataLine As String
Const delimiter As String = vbTab
Dim findPart As String
Dim replacePart As String
Dim tempDelimiter As Integer
Dim filePath As String
Set cntnr = MacroContainer
filePath = cntnr.Path & "\" & commonWordFileName
fileNum = FreeFile()
Open filePath For Input As #fileNum
Do While Not EOF(fileNum)
Line Input #fileNum, dataLine ' read in data 1 line at a time
' decide what to do with dataline,
' depending on what processing you need to do for each case
'Debug.Print dataLine
tempDelimiter = InStr(1, dataLine, delimiter)
If tempDelimiter <> 0 Then
findPart = Left(dataLine, tempDelimiter - 1)
replacePart = Mid(dataLine, tempDelimiter + 1)
If Len(findPart) > 0 And Len(replacePart) > 0 Then
findBin(replaceCount) = findPart
replaceBin(replaceCount) = replacePart
replaceCount = replaceCount + 1
End If
End If
Loop
Close #fileNum
'loop through our pairs running corresponding find/replaces
For i = 0 To replaceCount - 1
If i Mod 10 = 0 Then
DoEvents
End If
Debug.Print "Replacing """ & findBin(i) & """ with """ & replaceBin(i) & """"
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = findBin(i)
.replacement.text = replaceBin(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
Sub LoadAndExecuteWildcardReplacements()
'strings to search:
Dim findBin(255) As String
Dim replaceBin(255) As String
Dim replaceCount As Integer
Dim fileNum As Integer
Dim dataLine As String
Const delimiter As String = vbTab
Dim findPart As String
Dim replacePart As String
Dim tempDelimiter As Integer
Dim filePath As String
Set cntnr = MacroContainer
filePath = cntnr.Path & "\" & commonWordWildcardFileName
fileNum = FreeFile()
Open filePath For Input As #fileNum
Do While Not EOF(fileNum)
Line Input #fileNum, dataLine ' read in data 1 line at a time
' decide what to do with dataline,
' depending on what processing you need to do for each case
'Debug.Print dataLine
tempDelimiter = InStr(1, dataLine, delimiter)
If tempDelimiter <> 0 Then
findPart = Left(dataLine, tempDelimiter - 1)
replacePart = Mid(dataLine, tempDelimiter + 1)
If Len(findPart) > 0 And Len(replacePart) > 0 Then
findBin(replaceCount) = findPart
replaceBin(replaceCount) = replacePart
replaceCount = replaceCount + 1
End If
End If
Loop
Close #fileNum
'loop through our pairs running corresponding find/replaces
For i = 0 To replaceCount - 1
Debug.Print "Replacing """ & findBin(i) & """ with """ & replaceBin(i) & """"
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = findBin(i)
.replacement.text = replaceBin(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
Sub AddWordReplacement()
Const delimiter As String = vbTab
Const fileNa As String = "C:\Users\jeffr\Documents\Sion\Libros\ebookfindreplace.txt"
Dim resp
Dim fileNum As Integer
Dim dataLine As String
Dim findPart As String
Dim replacePart As String
resp = MsgBox("You have selected " & Len(Selection.text) & " characters, do you want to add this word the common word replacement file?", vbYesNo)
If resp = vbYes Then
fileNum = FreeFile()
findPart = Selection.text
replacePart = InputBox("Please enter the text you want to replace. Find/replace parameters are case sensitive and find whole word only.", , findPart)
Open fileNa For Append As #fileNum
dataLine = Replace(findPart, delimiter, "") & delimiter & Replace(replacePart, delimiter, "")
Debug.Print dataLine
Print #fileNum, dataLine
Close fileNum
End If
End Sub
Sub OpenWordReplacementFile()
'todo create the file if it doesn't exist
On Error GoTo jic
RetVal = Shell("C:\Program Files (x86)\Notepad++\notepad++.exe " & filePath, 1)
Exit Sub
jic:
RetVal = Shell("C:\WINDOWS\notepad.exe " & filePath, 1)
End Sub
Sub CommonWordReplacements()
resp = MsgBox("Do you want to check for incorrectly capitalized months in Spanish?", vbYesNo)
If resp = vbYes Then
FixCapitalizedMonthsInSpanish
End If
resp = MsgBox("Do you want to load the find/replace file from the Libros folder to cleanup common spelling/grammar errors?", vbYesNo)
If resp = vbYes Then
LoadAndExecuteFileReplacements
LoadAndExecuteWildcardReplacements
End If
End Sub
Sub MakeFootNotesAuto()
Dim f As Footnote
For Each f In ActiveDocument.Footnotes
f.Range.FootnoteOptions.NumberingRule _
= wdRestartContinuous
Next f
End Sub
Sub ParagraphBeforeHeadingDontKeepWithNext()
Dim lastP
Dim count
count = 0
For Each p In ActiveDocument.Paragraphs
count = count + 1
If p.Style = ActiveDocument.Styles("Heading 2") Or p.Style = ActiveDocument.Styles("Heading 1") Then
Debug.Print count
lastP.Format.KeepWithNext = False
End If
Set lastP = p
Next
End Sub
Sub AddChapterHyperlinks()
'gather list of h1 p's
'bookmark each h2
'gather list of h2 p ranges with corresponding text
'write at the beginning of each h1, hyperlinks to the h2s underneath
Dim lastP
Dim count
count = 0
Dim lastH1 As Range
Dim h2s(100) As Range
Dim isH3(100) As Boolean
Dim h2Count As Integer
Dim theText As String
Dim textToAdd As String
Dim formattedBookmark As Variant
Dim hyperlinkCount As Integer
If MsgBox("This script will add hyperlinks at the beginning of each chapter (immediately after each Heading 1), " & _
"do you want to continue?", vbYesNo) <> vbYes Then
Exit Sub
End If
If MsgBox("We usually eliminate any preexisting custom bookmarks to avoid conflicts, is this OK?", vbYesNo) = vbYes Then
EliminateBookmarks
Else
MsgBox "OK, we'll leave the old ones alone.", vbInformation
End If
BookmarkHeadings2
h2Count = 0
For Each p In ActiveDocument.Paragraphs
count = count + 1
If p.Style = ActiveDocument.Styles("Heading 1") Then
Debug.Print p.Range.text
'it's time to write the last h1's hyperlinks
If (h2Count > 0) Then
counter = h2Count - 1
For i = 0 To counter
theText = h2s(i).text
formattedBookmark = FormatBookmarkName(theText)
Debug.Print "Let's write some hyperlinks: " & theText & "," & formattedBookmark
If i = 0 Then
lastH1.Select
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
End If
hyperlinkCount = hyperlinkCount + 1
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:=formattedBookmark, ScreenTip:="", TextToDisplay:=theText
If isH3(h2Count) = True Then
Selection.Paragraphs.Indent
End If
Next i
End If
Set lastH1 = p.Range
h2Count = 0
ElseIf p.OutlineLevel = wdOutlineLevel2 Or p.OutlineLevel = wdOutlineLevel3 Then
Set h2s(h2Count) = p.Range
If p.OutlineLevel = wdOutlineLevel3 Then
isH3(h2Count) = True
End If
h2Count = h2Count + 1
End If
Next
'put in the last set of bookmarks
If (h2Count > 0) Then
counter = h2Count - 1
For i = 0 To counter
theText = h2s(i).text
formattedBookmark = FormatBookmarkName(theText)
Debug.Print "Let's write some hyperlinks: " & theText & "," & formattedBookmark
If i = 0 Then
lastH1.Select
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
End If
hyperlinkCount = hyperlinkCount + 1
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:=formattedBookmark, ScreenTip:="", TextToDisplay:=theText
Next i
End If
MsgBox "All set, we wrote " & Trim(CStr(hyperlinkCount)) & " hyperlinks.", vbInformation
End Sub
Sub AddIndexHyperlinks()
'presupposes the BookmarkHeadings2 has been called
'gather list of h1 p's
'bookmark each h2
'gather list of h2 p ranges with corresponding text
'write at the beginning of each h1, hyperlinks to the h2s underneath
Dim lastP
Dim count
count = 0
Dim lastH1 As Range
Dim h2s(100)
Dim h2Count
Dim theText As String
Dim textToAdd As String
Dim formattedBookmark As Variant
h2Count = 0
For Each p In ActiveDocument.Paragraphs
count = count + 1
If p.Style = ActiveDocument.Styles("Heading 1") Then
If Left(lastH1, 5) = "Index" Then
'it's time to write the last h1's hyperlinks
If (h2Count > 0) Then
counter = h2Count - 1
For i = 0 To counter
theText = h2s(i).text
formattedBookmark = FormatBookmarkName(theText)
Debug.Print "Let's write some hyperlinks: " & theText & "," & formattedBookmark
If i = 0 Then
lastH1.Select
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
End If
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:=formattedBookmark, ScreenTip:="", TextToDisplay:=theText
Next i
End If
End If
Set lastH1 = p.Range
h2Count = 0
ElseIf p.Style = ActiveDocument.Styles("Heading 2") Then
Set h2s(h2Count) = p.Range
h2Count = h2Count + 1
End If
Next
End Sub
Sub BookmarkIndex()
For Each p In ActiveDocument.Paragraphs
If p.Style = ActiveDocument.Styles("Heading 2") And Len(p.Range.text) <= 2 Then
Debug.Print FormatBookmarkName(p.Range.text)
ActiveDocument.Bookmarks.Add FormatBookmarkName(p.Range.text), p.Range
End If
Next
End Sub
Sub BookmarkHeadings2()
EliminateBookmarks
For Each p In ActiveDocument.Paragraphs
If p.Style = ActiveDocument.Styles("Heading 2") Then
'Debug.Print FormatBookmarkName(p.Range.Text)
ActiveDocument.Bookmarks.Add FormatBookmarkName(p.Range.text), p.Range
End If
Next
End Sub
Function FormatChapterBookmarkName(theText As String)
Dim result As String
result = "chapter_"
'find the number within the text
For i = 1 To Len(theText)
temp = Asc(Mid(theText, i, 1))
If temp >= 48 And temp < 58 Then
result = result & Chr(temp)
Else
Exit For
End If
Next i
FormatChapterBookmarkName = result
End Function
Function FormatQuestionBookmarkName(theText As String)
Dim result As String
result = "question_"
'find the number within the text
For i = 1 To Len(theText)
temp = Asc(Mid(theText, i, 1))
If temp >= 48 And temp < 58 Then
result = result & Chr(temp)
Else
Exit For
End If
Next i
FormatQuestionBookmarkName = result
End Function
Function FormatBookmarkName(theText As String)
Dim result
Dim ascii
theText = UCase(theText)
result = "b"
For i = 1 To Len(theText)
ascii = Asc(Mid(theText, i, 1))
If (ascii >= 48 And ascii <= 57) Or (ascii >= 65 And ascii <= 90) Then
result = result & Chr(ascii)
End If
Next
FormatBookmarkName = LCase(Left(result, 10))
End Function
Sub EliminateBookmarks()
For Each b In ActiveDocument.Bookmarks
If b.Name <> "toc" And Left(b.Name, 1) <> "_" Then
b.Delete
End If
Next
End Sub
Sub DeleteBlankParagraphAroundHeadings()
Dim lastWasH As Boolean
Dim latestPs(50) As Range
Dim pCount As Integer
Dim isBlank As Boolean
Dim lastH As String
Dim count As Integer
count = 0
lastWasH = False
lastH = ""
For Each p In ActiveDocument.Paragraphs
count = count + 1
isBlank = (Len(p.Range.text) = 1 And Asc(p.Range.text) = 13)
If lastWasH And isBlank Then
Debug.Print lastH
p.Range.text = ""
ElseIf p.OutlineLevel = wdOutlineLevel1 Or p.OutlineLevel = wdOutlineLevel2 Then
lastWasH = True
lastH = p.Range.text
For i = 0 To pCount - 1
Debug.Print lastH
latestPs(i).text = ""
Next
ElseIf isBlank Then
Set latestPs(pCount) = p.Range
pCount = pCount + 1
Else
lastWasH = False
lastH = ""
pCount = 0
End If
Next
End Sub
Sub PutManualPageBreakBeforeHeadings()
'
' Macro4 Macro
'
'
For Each p In ActiveDocument.Paragraphs
count = count + 1
If p.OutlineLevel = wdOutlineLevel1 Or p.OutlineLevel = wdOutlineLevel2 Then
p.Range.Select
Selection.HomeKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCharacter, count:=1
Selection.TypeParagraph
Selection.InsertBreak Type:=0
Selection.Delete Unit:=wdCharacter, count:=1
End If
Next
End Sub
Sub FormatHyperlinks()
For Each h In ActiveDocument.Hyperlinks
Debug.Print h.Address & "|" & h.SubAddress
h.Range.Font.Underline = wdUnderlineSingle
h.Range.Font.TextColor = wdColorGray625
h.Range.Case = wdTitleWord
Next
End Sub
Sub EliminateHyperlinks()
For Each h In ActiveDocument.Hyperlinks
Debug.Print h.Address & "|" & h.SubAddress
h.Delete
Next
End Sub
Sub ExtrapolateFootnotes()
'
' Macro1 Macro
'
'
Dim lastSelection As Range
Dim numberOfFootnotes As Integer
Dim footnoteRanges(200) As Range
Dim superscript As Boolean
tempResponse = InputBox("How many footnotes should we look for?")
If tempResponse = "" Then
Exit Sub
End If
numberOfFootnotes = CInt(tempResponse)
If MsgBox("Should we only look in superscripts?", vbYesNo) = vbYes Then
Selection.Find.ClearFormatting
With Selection.Find.Font
.superscript = True
.Subscript = False
End With
Selection.Find.replacement.ClearFormatting
With Selection.Find
.replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Else
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = Trim(CStr(i))
.replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End If
Selection.HomeKey Unit:=wdStory
Set lastSelection = Selection.Range
'go through the document always looking for the first occurance of
'the next number. If the user decides not to mark a footnote we
'should select the previous selection to avoid skipping over a
'whole bunch of numbers
For i = 1 To numberOfFootnotes
Do
Selection.Find.text = Trim(CStr(i)) & ">"
Selection.Find.Execute
response = MsgBox("Should we convert the selected number into a blank footnote? " & _
"If you click no we will continue searching for the same number. If you click cancel " & _
"we will start searching for the same number. Press Ctrl-X to exit the macro.", vbYesNoCancel)
If response = vbYes Then 'Add a blank footnote where the selected text was
Selection.TypeBackspace
Set lastSelection = Selection.Range
With Selection
With .FootnoteOptions
.Location = wdBottomOfPage
.NumberingRule = wdRestartContinuous
.StartingNumber = 1
.NumberStyle = wdNoteNumberStyleArabic
.LayoutColumns = 0
End With
.Footnotes.Add Range:=Selection.Range, Reference:=""
Set footnoteRanges(i) = Selection.Range
End With
End If
Loop Until response = vbYes Or response = vbCancel
lastSelection.Select
Next
End Sub
Sub StartingBookFromWpd()
'
' StartingBookFromWpd Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "^b"
.replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.PageSetup.Orientation = wdOrientPortrait
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(1.27)
.BottomMargin = CentimetersToPoints(1.27)
.LeftMargin = CentimetersToPoints(1.27)
.RightMargin = CentimetersToPoints(1.27)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.27)
.FooterDistance = CentimetersToPoints(1.27)
.PageWidth = CentimetersToPoints(21.59)
.PageHeight = CentimetersToPoints(27.94)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
ShowAll
ActiveDocument.ApplyQuickStyleSet2 ("Black & White (Classic)")
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "^-"
.replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.text = """"
.replacement.text = """"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
SetNormalStyle
End Sub
Sub FixBlankParagraphs()
'
' FixBlankParagraphs Macro
'
'
If MsgBox("This operation will eliminate blank paragraphs around headings 1 and 2 " & _
"and consolidate multiple blank spaces transforming 1 blank into none, " & _
"2 blanks into 1, and 3+ blanks into 2. Are you sure you want to continue?", vbYesNo) <> vbYes Then
Exit Sub
End If
'remove blank space characters from otherwise blank paragraphs
Selection.Find.ClearFormatting
With Selection.Find
.text = "[ ^09]{1,200}[^013]"
.replacement.text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'delete blank paragraphs around headings 1 and 2
DeleteBlankParagraphAroundHeadings
'Prep big spaces
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "[^013]{4,50}"
.replacement.text = "^p{2blankparagraphs}^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
'Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
'prep small spaces in text
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "^p^p^p"
.replacement.text = "^p{1blankparagraph}^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
'protect double paragraphs in verse areas
Selection.Find.ClearFormatting
With Selection.Find.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "^p^p"
.replacement.text = "^p{1blankparagraph}^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'eliminate formerlly small spaces
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "^p^p"
.replacement.text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'finalize big spaces
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "{2blankparagraphs}"
.replacement.text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'finalize small spaces
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "{1blankparagraph}"
.replacement.text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
If MsgBox("Finished removing excess blank paragraphs. Do you want to add manual page breaks before headings 1 and 2?") = vbYes Then
PutManualPageBreakBeforeHeadings
End If
MsgBox "Done. As a next step, prepare to delete all tabs and double spaces.", vbInformation
End Sub
Sub ReplaceTabsWithSpace()
Selection.Find.ClearFormatting
Selection.Find.replacement.ClearFormatting
With Selection.Find
.text = "^t"
.replacement.text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub EliminateMultipleSpaces()
'Eliminate spaces and tabs at the end of paragraphs
Selection.Find.ClearFormatting
With Selection.Find
.text = "[ ^09]{1,200}[^013]"
.replacement.text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False