Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-30-2024, 10:54 PM
tonykekw tonykekw is offline Pull all lists from document Windows 11 Pull all lists from document Office 2021
Novice
Pull all lists from document
 
Join Date: Jan 2024
Posts: 13
tonykekw is on a distinguished road
Post Pull all lists from document

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
practicing VBA everyday, if anyone has suggestions on learning VBA let me know, i dont want to ask to many Q. or spam help. thanks
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
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
Pull all lists from document Multilevel lists - Document starting with second level thara Word 2 05-02-2016 02:37 AM
Pull all lists from document How to have two different numbering lists in a document? saseymour Word 3 09-29-2014 11:30 AM
Several Multilevel Lists in a document Aston Word 4 10-07-2012 01:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:31 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