Sub CopyToListAlphabeticList() ' Paul Beverley - Version 25.11.25 ' Copies selected text into an alphabetic list ' N.B. Each item must have a single uppercase letter + Enter ' To check, switch visible formatting on. ' To locate list file (not case sensitive) ' keyWord = "queries" keyWord = "list" keyWord = "sheet" myTable = 2 wordsToAvoid = "switch" ' wordsToAvoid = "FRedit,switch" beepIfAlreadyListed = True Dim sourceText As Range Set sourceDoc = ActiveDocument wds = Split("," & LCase(wordsToAvoid), ",") CR = vbCr If Selection.Start = Selection.End Then If Selection = CR Then Selection.MoveLeft , 1 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 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 sSheetDoc In Application.Documents thisName = sSheetDoc.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 sSheetDoc 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 myChar = UCase(Left(myText, 1)) myNextChar = Chr(Asc(myChar) + 1) Set rng = sSheetDoc.Content ' First find ^pmyChar^p rng.Start = InStr(rng.Text, CR & myChar & CR) + 2 If myNextChar <> "[" Then ' Then find ^pmyNextChar^p myEnd = InStr(rng.Text, CR & myNextChar & CR) Else myEnd = InStr(rng.Text, CR & CR & CR) If myEnd = 0 Then rng.InsertBefore Text:=CR rng.MoveStart , 1 rng.MoveEnd , 1 End If End If rng.End = rng.Start + myEnd allText = CR & rng ' Check if it's already in the list gotItAlready = (InStr(allText & CR, CR & myText & CR) > 0) If gotItAlready = True Then If beepIfAlreadyListed = True Then Beep Exit Sub End If rng.MoveEnd , -1 myStart = rng.Start rng.InsertBefore Text:=myText & CR rng.Start = myStart rng.Sort CaseSensitive:=False End Sub