Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-03-2016, 11:02 AM
gmaxey gmaxey is offline Adding List Number to Acronym Table Windows 7 32bit Adding List Number to Acronym Table Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

I don't recall my earlier contributions to you macro and there is nothing wrong with Graham's method using collections. However, Graham and I do have different styles and in a case where it doesn't matter if items are repeated I would probably use an array:



Code:
Sub GetAcronyms()
'A basic Word macro coded by Greg Maxey http://gregmaxey.com/word_tips.html
Dim oTbl As Table
Dim oRng As Word.Range, oRngLP As Range
Dim oDoc As Word.Document
Dim lngIndex As Long, lngVal As Long
Dim arrVals() As String
  ReDim arrVals(3, 0)
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "<[A-Z]{1,4}>"
    .MatchWildcards = True
    While .Execute
      arrVals(0, UBound(arrVals, 2)) = oRng.Text
      arrVals(3, UBound(arrVals, 2)) = oRng.Sentences(1).Text
      If Not oRng.Paragraphs(1).Range.ListFormat.ListString = vbNullString Then
        arrVals(1, UBound(arrVals, 2)) = oRng.Information(wdActiveEndPageNumber)
        arrVals(2, UBound(arrVals, 2)) = oRng.Paragraphs(1).Range.ListFormat.ListString
      Else
        Set oRngLP = oRng.Duplicate
        Do
          On Error Resume Next
          Set oRngLP = oRngLP.Paragraphs(1).Previous.Range
          On Error GoTo 0
        Loop Until oRngLP.Paragraphs(1).Range.ListFormat.ListString <> vbNullString
        arrVals(1, UBound(arrVals, 2)) = oRngLP.Information(wdActiveEndPageNumber)
        arrVals(2, UBound(arrVals, 2)) = oRngLP.Paragraphs(1).Range.ListFormat.ListString
      End If
      ReDim Preserve arrVals(3, UBound(arrVals, 2) + 1)
      oRng.Collapse wdCollapseEnd
    Wend
  End With
  ReDim Preserve arrVals(3, UBound(arrVals, 2) - 1)
  Set oDoc = Documents.Add
  Set oTbl = oDoc.Tables.Add(oDoc.Range, 1, 4)
  With oTbl
    .Columns(1).Width = CentimetersToPoints(2.5)
    .Columns(2).Width = CentimetersToPoints(1.5)
    .Columns(3).Width = CentimetersToPoints(2.5)
    .Columns(4).Width = CentimetersToPoints(9)
  End With
  For lngIndex = 0 To UBound(arrVals, 2)
    For lngVal = 0 To 3
      oTbl.Rows.Last.Cells(lngVal + 1).Range.Text = arrVals(lngVal, lngIndex)
    Next lngVal
    If lngIndex < UBound(arrVals, 2) Then oTbl.Rows.Add
  Next lngIndex
  'oTbl.Sort ExcludeHeader:=False, FieldNumber:="Column 1", _
  SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
  FieldNumber2:="Column 3", SortFieldType2:=wdSortFieldNumeric, SortOrder2 _
  :=wdSortOrderAscending
lbl_Exit:
  Set oDoc = Nothing: Set oTbl = Nothing
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 12-03-2016, 08:59 PM
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
Default

Thank you Greg. But the last code you posted hangs. The new document is never created and the script never completes. I've tried to find what loop isn't closed, but the code is beyond my ability to follow.
Reply With Quote
Reply



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 08:56 AM.


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