Sub TableauxWord_vers_Excel()
'Déclarations variables
Dim ws As Worksheet, str_Path$, Nom_Fic$, wordApp As Object, wordDoc As Object
Dim table As Object, row As Object, cell As Object, lig&, xCol&
Set ws = ThisWorkbook.Sheets(1)
str_Path = "C:\Users\STAPLE\Documents\XLD_TESTS\" '<- chemin à adapter
lig = 1
On Error Resume Next
Set wordApp = CreateObject("Word.Application")
'boucle sur les *.docx
Nom_Fic = Dir(str_Path & "*.docx")
Do While Nom_Fic <> ""
ws.Cells(lig, 1).Value = Nom_Fic
Set wordDoc = wordApp.Documents.Open(str_Path & Nom_Fic)
For Each table In wordDoc.Tables
xCol = 2
For Each row In table.Rows
For Each cell In row.Cells
ws.Cells(lig, xCol).Value = CleanText(cell.Range.text)
xCol = xCol + 1
Next cell
lig = lig + 1
xCol = 2
Next row
Next table
wordDoc.Close False
Nom_Fic = Dir
Loop
wordApp.Quit
Set wordApp = Nothing
MsgBox "Recopie terminée.", vbInformation, "Import Word"
End Sub
Function CleanText(text As String) As String
CleanText = Replace(Replace(text, Chr(13), ""), Chr(7), "")
End Function