我需要从Word文档的页脚部分获取内容。尤其是我需要将页脚部分的表格内容转移到Excel文档中。我已经可以处理Word文档正文部分的表格了。如何将页脚部分的内容获取并添加到与文档正文内容相同的工作表或现有工作表中?
Sub ImportWordTable()
Dim sPfad As String
Dim appWord As Object
Dim strDatei As String
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Word
Dim jRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel
sPfad = "C:\Users\tim\Test2\" '<== adjust path
Application.ScreenUpdating = False
Set appWord = CreateObject("Word.Application")
appWord.Visible = True
strDatei = Dir(sPfad & "*.doc*")
Do While strDatei <> ""
appWord.Documents.Open sPfad & strDatei
'Read all tables of the document body
If appWord.ActiveDocument.tables.Count = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
Else
jRow = 0
Sheets.Add after:=Sheets(Worksheets.Count)
ActiveSheet.Name = strDatei & "Label-Text"
For TableNo = 1 To appWord.ActiveDocument.tables.Count
With appWord.ActiveDocument.tables(TableNo)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
jRow = jRow + 1
For iCol = 1 To .Columns.Count
On Error Resume Next
ActiveSheet.Cells(jRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
On Error GoTo 0
Next iCol
Next iRow
End With
jRow = jRow + 1
Next TableNo
End If
appWord.ActiveDocument.Close savechanges:=False
strDatei = Dir
Loop
appWord.Quit
Set appWord = Nothing
End Sub