#1
|
|||
|
|||
List acronyms from selected tables after them with style
Hello everyone,
I've been trying to adapt to my needs the acronymlister macros I could find but I am stuck. I have Word tables containing acronyms of 3 uppercase letters or more. I would like to run the macro on selected tables to find the acronyms within it and to list them right after each table. The list of acronyms should be formatted as Quote:
Quote:
Please find below the code I have been working on. I annotated where I think the code should be changed. Other options are welcome Code:
Sub ACRO_table Dim oTbl as Table Dim oCel as Cell Dim oRange as Range For Each oTbl in Selection.Range.Tables For Each oCel In oTbl.Range.Cells With oCel.RangeWith .find .text = "<[A-Z]{3,}>" .forward = True .Wrap = wdFindStop .Format = False .MatchCase = True .MatchWildCards = TrueDo While .Execute ' the following lines of code are wrong i.e. it copies the found acronyms in new cells with new cells oTbl.Range.collapse wdCollapseEnd oTbl.Range.Copy oCel.Range.PasteAndFormat (wdTableOriginalFormatting) Loop End with End with Next oCel Next oTbl Winrow Last edited by Winrow; 06-18-2022 at 02:18 AM. Reason: typo in title |
#2
|
||||
|
||||
Presumably, you're referring to one of the macros in:
https://www.msofficeforums.com/word-...generator.html https://www.msofficeforums.com/word-...soft-word.html The AcronymLister macro discussed in the first thread doesn't read anything from a table - it simply finds acronyms and creates a table of them. The AcronymManager macro discussed in the first thread processes acronyms listed in the last table in the document to ensure referencing consistency. The AcronymFinder macro discussed in the second thread processes acronyms listed in the first table in the document, but the table # is easily changed. The latter two macros also show how to read cell contents. See also: https://www.msofficeforums.com/word-...ym-finder.html & https://www.msofficeforums.com/word-...-spelling.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thank you! I didn’t see those links. It gives me some reading to create the macro.
Best, Winrow |
#4
|
|||
|
|||
Dear Macropod,
Dear all, I updated the code based on the ones within the links provided. It is now working on the assumption of a document containing two tables: the table containing the acronym with its definition and the table with acronym to find and list with their definition at the end of the document. I would like to avoid finding duplicates and having to type the known acronym definition located in the second column of table 1. Is there a way to do this? Code:
Sub ACRO_table3() Dim oTbl As Table, qTbl As Table Dim oRng As Range Dim strAcr As String, strFnd As String, strDef As String Dim i As Long, j As Long strAcr = "," Set oTbl = ActiveDocument.Tables(1) 'the 2-column table containing the acronym and definition Set qTbl = ActiveDocument.Tables(2) 'the table containing the acronyms to list with their definition Set oRng = ActiveDocument.Range.Characters.Last For i = 1 To oTbl.Rows.Count With oTbl.Cell(i, 1).Range strFnd = Left(.Text, Len(.Text) - 2) strAcr = strAcr & strFnd & "," End With Next i With qTbl.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Format = False .Forward = True .Text = "<[A-Z]{3,}>" .MatchWildcards = True .Execute End With Do While .Find.Found strFnd = .Text If .Characters.Last.Information(wdWithInTable) = True Then If InStr(strAcr, "," & strFnd & ",") <> 0 Then strAcr = strAcr & strFnd & "," strDef = Trim(InputBox("KNOWN Term Found: " & strFnd & vbCr & _ "Add to definitions?" & vbCr & _ "If yes, type the definition.")) If strDef <> vbNullString Then With oRng .Text = strFnd & " = " & strDef & "; " .Collapse wdCollapseEnd .Style = "Legend" .InsertParagraph End With End If ElseIf InStr(strAcr, "," & strFnd & ",") = 0 Then strAcr = strAcr & strFnd & "," strDef = Trim(InputBox("NEW Term Found: " & strFnd & vbCr & _ "Add to definitions?" & vbCr & _ "If yes, type the definition.")) If strDef <> vbNullString Then With oRng .Text = strFnd & " = " & strDef & ";" & vbNewLine .Collapse wdCollapseEnd .Style = "Legend" .HighlightColorIndex = wdYellow .InsertParagraph End With End If Else End If Else: Exit Do End If .Collapse wdCollapseEnd .Find.Execute Loop End With End Sub |
#5
|
||||
|
||||
Can you post a document containing the two tables that you want the macro to run on?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
||||
|
||||
If you use the The AcronymLister macro discussed in the first thread, that will create a table for you of all the found acronyms, plus it's attempt to work out what those acronyms mean.
After correcting those entries (and any erroneous document content identified), plus adding any new entries you might have, the AcronymManager macro discussed in the same thread will both processes acronyms listed in the last table in the document to ensure referencing consistency and add the referencing for any entries you've added. Thus, only one table is used - the one the first macro creates at the end of the document (though you could just create your own) and skip the AcronymLister macro.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Quote:
I have posted an example of the document if this helps. Please find attached. |
Tags |
acronymlister macro, word table |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cross-reference with full context a numbered list inside another multilevel list (list style) | MatLcq | Word | 0 | 02-01-2021 06:00 AM |
Creating a list of Acronyms / Abbreviations | daithy | Word | 4 | 03-12-2020 01:52 PM |
numbered list: bold when selected and fade when selected following number | village | PowerPoint | 0 | 11-08-2017 10:43 AM |
Macro to create list of acronyms | lsmcal1984 | Word | 3 | 09-04-2013 07:33 AM |
Macro to apply style to selected tables | ubns | Word | 1 | 08-02-2012 04:09 AM |