Option Explicit
Public Num_tab As Integer
Sub Recup_Tableaux()
Dim i As Integer, j As Integer, k As Integer, lg As Integer, cl As Integer, ligne As Integer, n_col As Integer
Dim S As String, T As Variant, ce As Object, num As String
Open_Word Word_A_Lire
ligne = 2
n_col = 0
With WordDoc
'----------------------------------------------Liste des tableaux-----------------------------------------
Dim texte As String, pres As Integer, a As String
pres = 2
For i = 1 To .Tables.Count
a = 0
' j = 1
' k = 2
lg = .Tables(i).Rows.Count
cl = .Tables(i).Columns.Count
ReDim T(1 To lg, 1 To cl)
For j = 1 To lg
For k = 1 To cl
S = ""
If Not Exist_cell(i, j, k) Then
num = WordDoc.Tables(i).Cell(j, k).Range.text
num = Replace(Replace(num, Chr(7), ""), Chr(13), Chr(10))
T(j, k) = num
texte = Left(num, 7)
If texte = "Etape :" Then
'MsgBox texte
ThisWorkbook.Sheets("Liste_tableaux").Cells(pres, 2) = num
a = 1
End If
If texte = "Objecti" And a = 1 Then
'MsgBox texte
ThisWorkbook.Sheets("Liste_tableaux").Cells(pres, 3) = num
End If
If texte = "Scénari" And a = 1 Then
'MsgBox texte
ThisWorkbook.Sheets("Liste_tableaux").Cells(pres, 1) = i
ThisWorkbook.Sheets("Liste_tableaux").Cells(pres, 4) = num
pres = pres + 1
End If
End If
Next k
Next j
Next i
Sheets("Liste_tableaux").Select
Columns("A:D").EntireColumn.AutoFit
Rows("1:" & i + 1).EntireRow.AutoFit
'----------------------------------------------Import tableaux-----------------------------------------
'Do While ligne <= Sheets("Liste_tableaux").Cells(Rows.Count, 1).End(xlUp).Row
For ligne = 2 To Sheets("Liste_tableaux").Cells(Rows.Count, 1).End(xlUp).Row
Num_tab = Sheets("Liste_tableaux").Cells(ligne, 1).Value
lg = .Tables(Num_tab).Rows.Count
cl = .Tables(Num_tab).Columns.Count
ReDim T(1 To lg, 1 To cl)
For j = 1 To lg
For k = 1 To cl
S = ""
If Not Exist_cell(Num_tab, j, k) Then
S = WordDoc.Tables(Num_tab).Cell(j, k).Range.text
S = Replace(Replace(S, Chr(7), ""), Chr(13), Chr(10))
T(j, k) = S
End If
Next k
Next j
ThisWorkbook.Sheets("Import").Cells(3, 1 + n_col).Resize(UBound(T, 1), UBound(T, 2)) = T
Sheets("Import").Select
Range(Cells(2, 1 + n_col), Cells(2, 3 + n_col)).MergeCells = True
Sheets("Import").Cells(2, 1 + n_col).Select
Mise_en_forme_tab
'ligne = ligne + 1
n_col = n_col + 4
Next ligne
'Loop
'---------------------------------------------------------------------------------------------------------
End With
'Close_Word
'ferme le document Word sans sauvegarde
WordDoc.Close False
'ferme l'application Word
WordApp.Quit
End Sub
Function Exist_cell(i As Integer, j As Integer, k As Integer) As Boolean
Dim S As String
Exist_cell = False
On Error GoTo errhdlr
S = WordDoc.Tables(i).Cell(j, k).Range.text
Exit Function
errhdlr:
Exist_cell = True
End Function