Skip to content

Instantly share code, notes, and snippets.

@githubyouser
githubyouser / TOCforCDL.bas
Created October 27, 2023 22:15
TOC for CDL (doubled page numbers)
Sub CreateTOCforCDL()
'Add page breaks to make all chapter titles start on an odd page number
Dim rng As Range
Dim pgNum As Integer
Set rng = ActiveDocument.Range
With rng.Find
.style = ActiveDocument.Styles("Heading 1")
.Forward = True
.Wrap = wdFindStop
@githubyouser
githubyouser / Arabic.bas
Created September 29, 2023 23:46
Arabic specific scripts for Word cleanup
Private Sub FormatArabicStyles()
Dim objUndo As UndoRecord
Set objUndo = Application.UndoRecord
objUndo.StartCustomRecord ("Format Arabic text styles")
Application.ScreenUpdating = False
'-----First clear formatting, then set styles-----'
'CLEAR FORMATTING
@githubyouser
githubyouser / EraseTextBoxes.bas
Created February 6, 2023 12:41
Word VBA: Convert text boxes to plain text
'https://answers.microsoft.com/en-us/msoffice/forum/all/removing-text-box-from-word-document-without/a4d02b2f-d168-48dc-960b-4a45cbe79d86
Sub EraseTextBoxes()
Dim RngDoc As Range, RngShp As Range, i As Long
With ActiveDocument
For i = .Shapes.Count To 1 Step -1
With .Shapes(i)
'If .Type = msoTextBox Then
'https://eileenslounge.com/viewtopic.php?p=28255#p28255
If .TextFrame.HasText = True Then
Set RngShp = .TextFrame.TextRange
@githubyouser
githubyouser / ModifyMarkdown.py
Created January 31, 2023 14:23
Modify a MD file from Word to add headings.
import sys
import re
with open(sys.argv[1], "r", encoding="utf-8") as input:
with open(sys.argv[2], "x", encoding="utf-8") as output:
for line in input:
clean = (line)
clean = re.sub('## \*\*(Lesson [0-9]+)\*\*(\n)', '# \\1\\2', clean) # Convert Lesson #s to H1s
clean = re.sub('\*\*\[(.*?)\]\{\.underline\}\*\*(\n)', '### \\1\\2', clean) # Convert underlined Word H1s to md H3s
clean = re.sub('\*\*\*(.*?)\*\*\*(\n)', '##### \\1\\2', clean) # Convert bold and italic headers to H5s
@githubyouser
githubyouser / FindShadedText.bas
Created January 31, 2023 14:21
Word VBA: Find shaded text and replace with underlining
'https://www.msofficeforums.com/word-vba/49481-remove-shading-specific-color-document-multiple-shading.html
Sub Macro5()
Dim iCol As Long
iCol = Selection.Shading.BackgroundPatternColor
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.ParagraphFormat.Shading.BackgroundPatternColor = iCol
.Replacement.Font.Underline = wdUnderlineSingle
@githubyouser
githubyouser / FindHighlightMultiple.bas
Last active September 28, 2022 17:52
Find an array of words and highlight them - Word VBA
'https://web.archive.org/web/20150420112826/http://help.lockergnome.com/office/Word-2007-Search-multiple-words-document--ftopict1010011.html
Sub HiLightList()
Application.ScreenUpdating = False
Dim vFindText
Dim r As Range
Dim i As Long
vFindText = Array("[!-:(0-9][0-9]{1,}[!-:,.)][!A-Z]", " ten[!a-z]", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred[!s]", "thousand[!s]", ",000,000")
'Add undo function - https://docs.microsoft.com/en-us/office/vba/word/Concepts/Working-with-Word/working-with-the-undorecord-object
Dim objUndo As UndoRecord
@githubyouser
githubyouser / Track2Formatting.bas
Created September 27, 2022 17:20
Convert Tracked Changes in MS Word to Formatted Text
'Source: https://answers.microsoft.com/en-us/msoffice/forum/all/word-2013-is-there-a-way-to-replace-tracked/adc5f04e-34d5-4423-b0ac-84d5548246be
Sub ConvertTrackedChangesToFormatting()
'Add undo function - https://docs.microsoft.com/en-us/office/vba/word/Concepts/Working-with-Word/working-with-the-undorecord-object
Dim objUndo As UndoRecord
Set objUndo = Application.UndoRecord
'Begin the custom undo record and provide a name for the record
objUndo.StartCustomRecord ("Convert Tracked Ch. to Formatting")
@githubyouser
githubyouser / openBibleRefs.bas
Last active September 12, 2022 20:23
Search BibleGateway.com for the selected reference
'https://www.mrexcel.com/board/threads/open-webpage-via-vba.832507/
Sub OpenWebpage()
'Catch the selected reference
Set myRef = Selection.Range
Dim URLa As String
Dim URLb As String
URLa = "https://www.biblegateway.com/passage/?search="
@githubyouser
githubyouser / ConvertParenth2ftntV3.bas
Last active August 25, 2022 21:49
Convert text (in parentheses) to a footnote [Word VBA]
'https://stackoverflow.com/a/29811973
Sub ConvertParentheses2FootnoteV3()
'Add undo function! 'https://docs.microsoft.com/en-us/office/vba/word/Concepts/Working-with-Word/working-with-the-undorecord-object
Dim objUndo As UndoRecord
Set objUndo = Application.UndoRecord
'Begin the custom undo record and provide a name for the record
objUndo.StartCustomRecord ("Replace parenth. with footnote")