![]() |
#1
|
|||
|
|||
![]()
VBA for MS Word
trying to extract all lists with their respected data. a) list type b) list Content c) heading level this data gets added to a new word doc for the time being. I am getting stuck on how to go about pulling the lists. ( I use the bult in MS Word list types). Eventually I would like to pull the data and move it to an excel sheet. Code:
Sub ExtractAllLists() Dim aRng As Range Dim aRngHeader As Range Dim aDoc As Document Dim aDocNew As Document Dim aTbl As Table Dim aRow As Row Dim sNum As String Set aDoc = ActiveDocument Set aRng = aDoc.Range Set aDocNew = Documents.Add Set aTbl = aDocNew.Tables.Add(aDocNew.Range, 1, 3) aTbl.Cell(1, 1).Range.Text = "List Type" aTbl.Cell(1, 2).Range.Text = "List Contents" aTbl.Cell(1, 3).Range.Text = "Heading" With aRng.Find .ClearFormatting .Replacement.ClearFormatting .Text = "" .Forward = True Do While .Execute aRng.Start = aRng.Paragraphs(1).Range.Start Set aRow = aTbl.Rows.Add If aRng.ListFormat.ListType <> wdListNoNumbering Then aRow.Cells(2).Range.FormattedText = aRng.FormattedText Else aRow.Cells(2).Range.Text = aRng.Text End If ' stuck here ' Retrieve heading information Set aRngHead = aRng.GoToPrevious(wdGoToHeading) aRngHead.End = aRngHead.Paragraphs(1).Range.End - 1 aRow.Cells(3).Range.Text = aRngHead.ListFormat.listString & vbTab & aRngHead.Text ' Move to the end of the range aRng.Collapse Direction:=wdCollapseEnd aRng.End = aDoc.Range.End |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA script to pull data into existing document | Formd | Word VBA | 4 | 05-11-2021 03:47 AM |
Multiple Multi-Level Lists in Same Document | TimGS | Word | 6 | 05-15-2018 05:29 AM |
![]() |
thara | Word | 2 | 05-02-2016 02:37 AM |
![]() |
saseymour | Word | 3 | 09-29-2014 11:30 AM |
Several Multilevel Lists in a document | Aston | Word | 4 | 10-07-2012 01:50 AM |