[
    {
        "role": "user",
        "content": "I%20need%20a%20VBA%20Word%20macro%20to%20number%20the%20passages%20in%20a%20document.%20The%20document%20consists%20of%20121%20passages.%20Unfortunately%2C%20they%20are%20not%20numbered.%20Each%20passage%20ends%20with%20a%20line%20like%20this%3A%20*%20*%20*.%20I%20have%20numbered%20the%20first%20passage%2C%20placing%20the%20number%201%20before%20it.%20So%20the%20first%20number%20the%20macro%20will%20add%20will%20be%20to%20the%20second%20passage%2C%20placing%20the%20number%202%20before%20it%2Cand%20the%20last%20one%20will%20be%20the%20120th%20action%20it%20will%20take%2C%20prepending%20%23121%20to%20the%20final%20passage.%20Then%20remind%20me%20how%20to%20use%20the%20macro."
    },
    {
        "role": "assistant",
        "content": "Here\u2019s a VBA macro for Word that numbers each of your passages by inserting \u201c#2\u201d, \u201c#3\u201d, \u2026 up to \u201c#121\u201d before each passage (except the first which you've already numbered as \u201c#1\u201d). I assume each passage ends with a line consisting of \u201c* * *.\u201d exactly (three asterisks separated by spaces, then a period)\u2014so the macro can reliably detect passage endings.  \n\n---\n\n## VBA Macro Code\n\n```vb\nSub NumberPassages()\n    Dim para As Paragraph\n    Dim doc As Document\n    Dim rng As Range\n    Dim passageCount As Long\n    Dim found As Boolean\n    \n    Set doc = ActiveDocument\n    passageCount = 2  ' We already have #1 before first passage\n    \n    ' Start from the beginning of the doc\n    Set rng = doc.Content\n    rng.Start = 0\n    rng.End = 0\n    \n    ' Loop through paragraphs\n    For Each para In doc.Paragraphs\n        Dim txt As String\n        txt = Trim(para.Range.Text)\n        \n        ' Check if this paragraph is the \"* * *.\" line\n        If txt = \"* * *.\" Then\n            ' Move to the paragraph after this one: that's the start of next passage\n            Dim nextParaIndex As Long\n            nextParaIndex = para.Index + 1\n            If nextParaIndex <= doc.Paragraphs.Count Then\n                Dim targetPara As Paragraph\n                Set targetPara = doc.Paragraphs(nextParaIndex)\n                \n                ' Insert \"#<number>\" at beginning\n                targetPara.Range.InsertBefore \"#\" & passageCount & \" \"\n                \n                passageCount = passageCount + 1\n                ' Stop if we've reached 121\n                If passageCount > 121 Then Exit For\n            End If\n        End If\n    Next para\n    \n    MsgBox \"Numbering complete. Last number used: #\" & (passageCount - 1)\nEnd Sub\n```\n\n---\n\n## How the Macro Works, Step by Step\n\n1. It assumes that the first passage is already numbered as `#1`;\n2. It sets a counter `passageCount = 2`;\n3. It loops through all paragraphs in the document:\n   - When it finds a paragraph whose text is exactly `* * *.` (trimmed),\n   - It takes the **next** paragraph (if there is one),\n   - Inserts `#<current passageCount> ` at the very beginning of that next paragraph;\n   - Increments `passageCount`;\n   - Stops once `passageCount` would exceed 121 (since you have 121 passages in total).\n4. Finally, it displays a message box with the last number used, to confirm everything.\n\n---\n\n## How to Use the Macro in Word\n\n1. Open your Word document (make sure you have a backup, just in case).\n2. Press `Alt + F11` to open the VBA editor.\n3. In the VBA editor, go to **Insert \u2192 Module**.\n4. Copy the macro code above into the module window.\n5. Close the VBA editor.\n6. Back in Word, press `Alt + F8` to open the \u201cMacro\u201d dialog.\n7. Select `NumberPassages` from the list and click **Run**.\n8. Let it run: it will insert numbering `#2`, `#3`, \u2026 up to `#121` appropriately.\n\n---\n\n## Possible Adjustments (if needed)\n\n- If the delimiter line is slightly different (e.g. `***.` or extra spaces), you may need to adjust the `If txt = \"* * *.\"` line\u2014perhaps use `If InStr(txt, \"* * *.\") > 0 Then` to detect more loosely.\n- If some passages are separated by empty lines or non-paragraph breaks, you may have to adapt to check for blank paragraphs or other markers.\n- If you want numbering inside the same paragraph that begins the passage (rather than always \u201cnext paragraph\u201d), you might detect the passage-start differently.\n\n---\n\nIf you like, I can give you a version that handles slight variations (e.g. spaces, blank lines, different punctuation), or one that shows in preview before making changes. Would you want that?"
    }
]