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 40 41 42
| Sub ImportWordTable()
' Nécessite d'activer la reference Microsoft word xx.x 0bject Library
' Déclaration des variables & constante
Dim FileName As Variant
Dim oDoc As Word.Document
Dim oWrd As Word.Application
Dim Folder As String, FullName
'
FileName = Application.GetOpenFilename("Word documents (*.doc*), *.doc*")
If FileName = False Then Exit Sub
Set oWrd = New Word.Application
With oWrd: .ShowMe: .Visible = True: End With
' Ouvre le document Word (Fichier.doc)
Set oDoc = oWrd.Documents.Open(FileName, ReadOnly:=True)
With oDoc
If .Tables.Count > 1 Then 'verifie si le document possede bien le tableau
.Tables(1).Range.Copy
Debug.Print ThisWorkbook.Sheets(1).Range("A1").Address
ThisWorkbook.Sheets(1).Paste
Else:
MsgBox "Le document sélectionné : " & vbCrLf & FileName & vbCrLf & _
"ne posséde pas le tableau spécifié", vbExclamation, "Erreur"
End If
End With
' Dans tous les cas, on ferme proprement
oDoc.Close False
oWrd.Application.Quit
Set oWrd = Nothing: Set oDoc = Nothing
End Sub |
Partager