1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Sub import_table_a1()
Dim wb As Workbook
Dim ws As Worksheet
Dim sChemin As String
Dim sNomFichier As String
Dim WApp As Object, WDoc As Object
Dim i As Integer, j As Integer
Dim Cible As Variant
Set wb = ThisWorkbook
Set ws = wb.Sheets(1)
sChemin = ThisWorkbook.Path & "\" ' le fichier Word se trouvent dans le même répertoire que le fichier Excel
sNomFichier = "test.docx"
Set WApp = CreateObject("Word.Application")
WApp.Visible = True
Application.ScreenUpdating = False
Set WDoc = WApp.Documents.Open(sChemin & sNomFichier) 'ouvre le document Word
For i = 1 To WDoc.Tables(1).Rows.Count
For j = 1 To WDoc.Tables(1).Columns.Count
Cible = WDoc.Tables(1).Columns(j).Cells(i)
ws.Cells(i, j) = _
Application.WorksheetFunction.Substitute(Cible, vbCr, vbLf)
ws.Cells(i, j) = _
Left(ws.Cells(i, j), Len(ws.Cells(i, j)) - 1)
Next j
Next i
Application.ScreenUpdating = True
WApp.Quit
End Sub |
Partager