Sub CopyToListAlphabetic() ' Paul Beverley - Version 26.04.25 ' Copies selected text into an alphabetic list file ' Exact capitalisation(i.e. case sensitive) ' Must be in style "Heading 3" followHeading = "Word list" ' To locate list file (not case sensitive) ' keyWord = "queries" keyWord = "list" keyWord = "sheet" wordsToAvoid = "switch" ' wordsToAvoid = "FRedit,switch" beepIfAlreadyListed = True ' copyWholePara = True copyWholePara = False includeFormatting = False ' includeFormatting = True goBackToSource = True Dim sourceText As Range Set thisDoc = ActiveDocument wds = Split("," & LCase(wordsToAvoid), ",") If Selection.Start = Selection.End Then If Selection = vbCr Then Selection.MoveLeft , 1 If copyWholePara = True Then Selection.Expand wdParagraph Else Set rng = Selection.Range.Duplicate rng.Expand wdWord rng.MoveEnd wdWord, 1 chkWd = rng.Words.Last If chkWd = "-" Then rng.MoveEnd wdWord, 2 chkWd = rng.Words.Last If chkWd = "-" Then rng.MoveEnd wdWord, 1 Else rng.MoveEnd wdWord, -1 End If Else rng.MoveEnd wdWord, -1 End If DoEvents Do While InStr(ChrW(8217) & "' ", Right(rng.Text, 1)) > 0 rng.MoveEnd , -1 DoEvents Loop rng.Select End If Else Set rng = Selection.Range.Duplicate rng.Collapse wdCollapseEnd rng.MoveEnd , -1 rng.Expand wdWord Do While InStr(ChrW(8217) & "' ", Right(rng.Text, 1)) > 0 rng.MoveEnd , -1 DoEvents Loop Selection.Collapse wdCollapseStart Selection.Expand wdWord Selection.Collapse wdCollapseStart rng.Start = Selection.Start rng.Select End If Set sourceText = Selection.Range.Duplicate myText = sourceText.Text Selection.Collapse wdCollapseEnd gottaList = False For Each myDoc In Application.Documents thisName = myDoc.Name nm = LCase(thisName) gottaList = False If InStr(nm, LCase(keyWord)) > 0 Then gottaList = True For i = 1 To UBound(wds) If InStr(nm, wds(i)) > 0 Then gottaList = False Next i If gottaList = True Then Exit For Next myDoc CR = vbCr: CR2 = CR & CR If gottaList = False Then Beep myResponse = MsgBox("Can't find a list/stylesheet." & CR2 & _ "Filename must include: >" & keyWord & "<", vbExclamation _ + vbOKOnly, "CopyToListAlphabetic") Exit Sub End If ' Decide where to put the item Set rng = myDoc.Content With rng.Find .ClearFormatting .Replacement.ClearFormatting .Text = "[^12^13]" & followHeading .Wrap = wdFindStop .Forward = True .Replacement.Text = "" .MatchCase = True .MatchWildcards = True .Execute DoEvents End With If rng.Find.Found = False Then myResponse = MsgBox("Can't find the heading:" & CR2 & _ followHeading, vbExclamation + vbOKOnly, "CopyToListAlphabetic") If goBackToSource = False Then myDoc.Activate Exit Sub End If rng.Expand wdParagraph listStart = rng.End rng.Collapse wdCollapseStart ' Check if it's already in the list Debug.Print rng With rng.Find .ClearFormatting .Replacement.ClearFormatting .Text = "^p" & myText & "^p" .Wrap = wdFindStop .MatchWildcards = False .Execute DoEvents End With If rng.Find.Found = True Then If beepIfAlreadyListed = True Then Beep If goBackToSource = False Then myDoc.Activate Exit Sub End If rng.Start = listStart rng.End = myDoc.Content.End If LCase(rng) <> UCase(rng) Then For i = 1 To rng.Paragraphs.Count myNextItem = Replace(rng.Paragraphs(i).Range.Text, vbCr, "") If LCase(myNextItem) > LCase(myText) Or _ LCase(myNextItem) = UCase(myNextItem) Then Set rng = rng.Paragraphs(i).Range.Duplicate Exit For End If Next i End If rng.Collapse wdCollapseStart ' Paste it in If includeFormatting = True Then rng.FormattedText = sourceText.FormattedText If InStr(myText, vbCr) = 0 Then rng.InsertAfter vbCr End If Else rng.InsertAfter myText If InStr(myText, vbCr) = 0 Then rng.InsertAfter vbCr End If rng.Collapse Direction:=wdCollapseEnd rng.Select rng.Revisions.AcceptAll If goBackToSource = False Then thisDoc.Activate End Sub