Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-02-2016, 07:26 AM
SerenityNetworks SerenityNetworks is offline Adding List Number to Acronym Table Windows 10 Adding List Number to Acronym Table Office 2016
Advanced Beginner
Adding List Number to Acronym Table
 
Join Date: May 2005
Location: Allen, Texas, USA
Posts: 37
SerenityNetworks
Question Adding List Number to Acronym Table

I've been using Greg and Graham's macro to generate an acronym list. It works great. But I'd like to add a column that provides the list number under which the acronym falls. I'm not a coder and have no idea how to accomplish this task.



Code:
For example, on page 1 we have:
1.     text
1.1    text
       RO Real Options
1.2    text
1.2.1  text
       BOB Big Ol' Bill
1.2.2  Syzygy Goes Wild (SGW)
       text
1.3    text

I would like returned:
RO   1    1.1   RO Real Options
BOB  1  1.2.1   BOB Big Ol' Bill
SGW  1  1.2.2   Syzygy Goes Wild (SGW)
How do I modify the code below to accomplish this? I'm thinking I need another sub to find the list number above or at the current location.

Thank you in advance,
Andrew

Code:
Sub GetAcronymsTEST()
     'A basic Word macro coded by Greg Maxey
     'http://gregmaxey.mvps.org/word_tips.html
     'Modified by Graham Mayor
     'http://www.gmayor.com
    Dim oCol As New Collection
    Dim oColPN As New Collection
    Dim oColLN As New Collection                    'added (for list number)
    Dim oColTxt As New Collection
    Dim oTable As Table
    Dim oCell As Range
    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
        While .Execute
            oCol.Add oRng.Text
            oColTxt.Add oRng.Sentences(1).Text
            oColPN.Add oRng.Information(wdActiveEndPageNumber)
            'call a sub to find previous Paragraphs(1).Range.ListFormat.ListString and put it here
            oRng.Collapse wdCollapseEnd
        Wend
    End With
    Set oDoc = Documents.Add
    Set oTable = oDoc.Tables.Add(oDoc.Range, 1, 4) 'changed 3 to 4
    oTable.Columns(1).Width = CentimetersToPoints(2.5)
    oTable.Columns(2).Width = CentimetersToPoints(1.5)
    oTable.Columns(3).Width = CentimetersToPoints(2.5)  'added
    oTable.Columns(4).Width = CentimetersToPoints(9)
     
    For lngIndex = 1 To oCol.Count
        Set oCell = oTable.Rows.Last.Cells(1).Range
        oCell.End = oCell.End - 1
        oCell.Text = oCol(lngIndex)
        Set oCell = oTable.Rows.Last.Cells(2).Range
        oCell.End = oCell.End - 1
        oCell.Text = oColPN(lngIndex)
        Set oCell = oTable.Rows.Last.Cells(3).Range
        oCell.End = oCell.End - 1
        oCell.Text = oColLN(lngIndex)
        Set oCell = oTable.Rows.Last.Cells(4).Range     'added
        oCell.End = oCell.End - 1                       'added
        oCell.Text = oColTxt(lngIndex)                  'added
        If lngIndex < oCol.Count Then oTable.Rows.Add
    Next lngIndex
     
    oTable.Sort ExcludeHeader:=False, FieldNumber:="Column 1", _
    SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
    FieldNumber2:="Column 2", SortFieldType2:=wdSortFieldNumeric, SortOrder2 _
    :=wdSortOrderAscending
     
lbl_Exit:
    Set oDoc = Nothing
    Set oRng = Nothing
    Set oTable = Nothing
    Set oCell = Nothing
    Set oCol = Nothing
    Set oColPN = Nothing
    Set oColTxt = Nothing
    Exit Sub
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding tables based on a number given in a form coba Word VBA 5 12-26-2015 07:05 PM
Adding List Number to Acronym Table Acronym Finder Cray_Z Word VBA 14 09-22-2014 11:42 PM
Adding List Number to Acronym Table How to create a table with a number of line depending a number entered by user Cellendhyll Word Tables 3 07-10-2014 05:49 AM
Adding List Number to Acronym Table List Style Numbering picks up out of order number from LATER list spthomas Word 12 12-16-2013 05:23 PM
Adding List Number to Acronym Table Adding Characters to Page Number Daved2424 Word 6 01-22-2011 07:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:48 PM.


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