![]() |
#2
|
|||
|
|||
![]()
I'm trying to figure this out, but I'm having no substantial success. I can use the following, but it only grabs the sentence after the first acronym found and then repeats it for every acronym. At the very least I need to return the sentence where the acronym appears, not the sentence after.
I'd really appreciate any help. Thanks, Andrew Code:
Sub GetAcronyms() 'A basic Word macro coded by Greg Maxey 'https://www.msofficeforums.com/word/17843-macro-create-list-acronyms.html Dim oCol As New Collection Dim oColPN As New Collection Dim oColTxt As New Collection 'new Dim strTxt As String 'new Dim oRng As Word.Range Dim oDoc As Word.Document Dim lngIndex As Long Set oRng = ActiveDocument.Range With oRng.Find .Text = "<[A-Z]{1,4}>" .MatchWildcards = True 'new With Selection ' Expand selection to current sentence. .Expand Unit:=wdSentence End With strTxt = Selection.Text While .Execute On Error Resume Next oCol.Add oRng.Text, oRng.Text 'Uncomment the following to add the page number of the acronym. Also swap commented row near bottom. If Err.Number = 0 Then oColPN.Add oRng.Information(wdActiveEndPageNumber) oColTxt.Add strTxt 'new End If On Error GoTo 0 oRng.Collapse wdCollapseEnd Wend End With Set oDoc = Documents.Add For lngIndex = 1 To oCol.Count 'oDoc.Range.InsertAfter oCol(lngIndex) & " " & oColPN(lngIndex) & vbCr 'original oDoc.Range.InsertAfter oCol(lngIndex) & vbTab & oColPN(lngIndex) & vbTab & oColTxt(lngIndex) & vbCr 'oDoc.Range.InsertAfter oCol(lngIndex) & vbCr Next lngIndex End Sub |
Tags |
acronyms, definitions |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
mars1886 | Word VBA | 15 | 03-30-2022 06:56 AM |
Asking about In Text Pictures, and Text surrounding | azbaby543 | Word | 0 | 02-25-2016 11:22 AM |
![]() |
velour99 | Word | 1 | 07-22-2015 11:39 AM |
![]() |
skarden | Word | 1 | 12-12-2011 10:39 PM |
creating border to image without surrounding text | gib65 | Drawing and Graphics | 5 | 08-15-2011 09:17 AM |