Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2022, 02:17 AM
Winrow Winrow is offline List acronyms from selected tables after them with style Windows 10 List acronyms from selected tables after them with style Office 2016
Novice
List acronyms from selected tables after them with style
 
Join Date: Jun 2022
Posts: 5
Winrow is on a distinguished road
Question 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:
ABC =
, use semi-colon as separator and, if at all possible, applied the Word style
Quote:
legend
.

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.Range
With .find .text = "<[A-Z]{3,}>" .forward = True .Wrap = wdFindStop .Format = False .MatchCase = True .MatchWildCards = True
Do 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
Many thanks in advance.

Winrow

Last edited by Winrow; 06-18-2022 at 02:18 AM. Reason: typo in title
Reply With Quote
  #2  
Old 06-18-2022, 04:12 AM
macropod's Avatar
macropod macropod is offline List acronyms from selected tables after them with style Windows 10 List acronyms from selected tables after them with style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 06-18-2022, 09:49 AM
Winrow Winrow is offline List acronyms from selected tables after them with style Windows 10 List acronyms from selected tables after them with style Office 2016
Novice
List acronyms from selected tables after them with style
 
Join Date: Jun 2022
Posts: 5
Winrow is on a distinguished road
Default

Thank you! I didn’t see those links. It gives me some reading to create the macro.

Best,

Winrow
Reply With Quote
  #4  
Old 06-21-2022, 01:36 PM
Winrow Winrow is offline List acronyms from selected tables after them with style Windows 10 List acronyms from selected tables after them with style Office 2016
Novice
List acronyms from selected tables after them with style
 
Join Date: Jun 2022
Posts: 5
Winrow is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 06-21-2022, 04:18 PM
Guessed's Avatar
Guessed Guessed is offline List acronyms from selected tables after them with style Windows 10 List acronyms from selected tables after them with style Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Can you post a document containing the two tables that you want the macro to run on?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #6  
Old 06-21-2022, 04:44 PM
macropod's Avatar
macropod macropod is offline List acronyms from selected tables after them with style Windows 10 List acronyms from selected tables after them with style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 06-25-2022, 03:27 AM
Winrow Winrow is offline List acronyms from selected tables after them with style Windows 10 List acronyms from selected tables after them with style Office 2016
Novice
List acronyms from selected tables after them with style
 
Join Date: Jun 2022
Posts: 5
Winrow is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Can you post a document containing the two tables that you want the macro to run on?
I have found the "vbBinaryCompare" which (I think) is the key factor but I cannot see how to include it for what I would like to achieve.

I have posted an example of the document if this helps. Please find attached.
Attached Files
File Type: docx Acro_list.docx (17.1 KB, 7 views)
Reply With Quote
Reply

Tags
acronymlister macro, word table

Thread Tools
Display Modes


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
List acronyms from selected tables after them with style 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
List acronyms from selected tables after them with style Macro to create list of acronyms lsmcal1984 Word 3 09-04-2013 07:33 AM
List acronyms from selected tables after them with style Macro to apply style to selected tables ubns Word 1 08-02-2012 04:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft