Skip to content

Instantly share code, notes, and snippets.

@sliminality
Last active August 21, 2023 22:22
Show Gist options
  • Save sliminality/cb13b4ad725ed4eb16d7 to your computer and use it in GitHub Desktop.
Save sliminality/cb13b4ad725ed4eb16d7 to your computer and use it in GitHub Desktop.
Verbatim macro to emphasize the first letter of each word in a selection

Installation

Navigate to Verbatim Settings -> Admin -> Templates Folder, right click Debate.dotm, and choose Open (NOT “New”).

Microsoft Word should open. In the ribbon, navigate to Developer -> Visual Basic; a new window should pop up.

In the sidebar: Verbatim(Debate) -> Modules -> Formatting and double click on Formatting The first lines of the main window should say:

Option Explicit
Sub UnderlineMode(control As IRibbonControl, pressed As Boolean)

Scroll to the very bottom of this window. On a new line, copy paste the following:

Sub FormatAcronym()
 
    Dim i As Integer
 
    For i = 1 To Selection.Words.Count
        Dim word As String
        word = Selection.Words(i)
        If word <> "-" Then
            Selection.Words(i).Characters(1).Style = "Emphasis"
        End If
    Next
 
End Sub

Ctrl-S and exit the VBA editor.

Back in main Word window, go to File -> Options -> Customize Ribbon -> Keyboard Shortcuts: Customize. In the drop down list make sure Debate.dotm is selected (not Normal.dotm); in the left scrolling list scroll all the way down and choose Macros, and in the right scrolling list choose FormatAcronym. Assign it to a keyboard shortcut of your choosing (I used Alt+F10).

Enjoy never having to manually emphasize "Air Sea Battle" ever again

Changelog

21 August 2023: Handle hyphens better (e.g. "no-first-use" → "no-first-use" instead of "no-first-use").

Paste without newlines

(for PDFs etc.)

This creates two bindable macros:

  • PasteNoReturnsNewline, which compresses the paragraph then inserts a newline so you're ready to paste the next paragraph
  • PasteNoReturnsNewspace does the same but inserts a space instead of a newline (useful if the paragraph continues onto the next page of the PDF)

I put this under Formatting module. idk why it's so slow but I'll fix it later

Sub PasteNoReturns(breakParagraph As Boolean)
' Same as F2 but remove returns @

    Dim Clipboard As New DataObject
    Dim PasteText
    
    'Assign clipboard contents to string if text
    Clipboard.GetFromClipboard
    If Clipboard.GetFormat(1) = False Then Exit Sub
    PasteText = Clipboard.GetText(1)
        
    Selection = PasteText
    
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Execute Replace:=wdReplaceAll
    
        ' Compress spaces, although this seems slow in retrospect, maybe use a regex?
        .Text = "  "
        .Replacement.Text = " "
        While InStr(Selection, "  ")
            .Execute Replace:=wdReplaceAll
        Wend
        
        ' Clean up trailing hyphens.
        .Text = "- "
        .Replacement.Text = ""
        .Execute Replace:=wdReplaceAll
        
        ' Trim leading spaces.
        If Selection.Characters(1) = " " And _
        Selection.Paragraphs(1).Range.Start = Selection.Start Then _
        Selection.Characters(1).Delete
    End With
    
    ' End with either a newline or whitespace.
    If breakParagraph Then
        Selection.InsertParagraphAfter
    Else
        Selection.InsertAfter (" ")
    End If
    
    Selection.Collapse 0

End Sub

Sub PasteNoReturnsNewline()
' Same as F2 but remove returns and insert a newline @slim
    Call Formatting.PasteNoReturns(True)
End Sub

Sub PasteNoReturnsNewspace()
' Same as F2 but remove returns and insert a whitespace @slim
    Call Formatting.PasteNoReturns(False)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment