简体   繁体   中英

Getting Word document headings into Excel

I'm trying to import the headings of word document to an excel spreadsheet.

Word Headings:

1 Heading 1

1.1 Heading 2

1.1.1 Heading 3

The spreadsheet would have columns Heading 1, Heading 2, Heading 3

表格示例

I'm sorry there was a big mistake in my first answer. You don't need the application object to create your word app.

The correct code see below:

Option Explicit

Public Sub Test_ReadWordDocument()
    Dim WordApp     As Object
    Dim WordDoc     As Object
    Dim Para        As Object

    Set WordApp = CreateObject("Word.Application")
    Set WordDoc = WordApp.Documents.Open("...\TestReadWordDoc.docx")

    For Each Para In WordDoc.Paragraphs
        Debug.Print Para.Range.Text
    Next Para

End Sub

Result:

Heading1
Heading2
Heading3
Lore ipsum Lore ipsum 
Lore ipsum 
Lore ipsum 
Lore ipsum

From there you can go on. Use the locals window to inspect the late binded objects. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM