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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
Sub ParserDocument()
Dim xlApp As Excel.Application
Dim xlWb As Excel.Workbook
Dim xlWs As Excel.Worksheet
Dim para As Paragraph
Dim intVariete As Integer
'affectation des objets Excel
Set xlApp = New Excel.Application
Set xlWb = xlApp.Workbooks.Add
Set xlWs = xlWb.Worksheets(1)
'Au moins une variété de graines
intVariete = 1
For Each para In ActiveDocument.Paragraphs
If Len(para.Range.Text) > 2 Then
'Traitement à faire
'Debug.Print RTrim(para.Range.Words(1)) & " - " & Len(para.Range.Words(1))
Select Case Left(para.Range.Words(1), 4)
Case "DESC"
xlWs.Cells(intVariete, 2) = Mid(para.Range.Text, 15, Len(para.Range.Text) - 1)
Case "CHOI"
xlWs.Cells(intVariete, 3) = Mid(para.Range.Text, 16, Len(para.Range.Text) - 1)
Case "SEMI"
xlWs.Cells(intVariete, 4) = Mid(para.Range.Text, 9, Len(para.Range.Text) - 1)
Case "CULT"
xlWs.Cells(intVariete, 5) = Mid(para.Range.Text, 11, Len(para.Range.Text) - 1)
Case "RECO"
xlWs.Cells(intVariete, 6) = Mid(para.Range.Text, 11, Len(para.Range.Text) - 1)
Case "CONS"
xlWs.Cells(intVariete, 7) = Mid(para.Range.Text, 12, Len(para.Range.Text) - 1)
Case "FLOR"
xlWs.Cells(intVariete, 8) = Mid(para.Range.Text, 13, Len(para.Range.Text) - 1)
Case "UTIL"
xlWs.Cells(intVariete, 9) = Mid(para.Range.Text, 15, Len(para.Range.Text) - 1)
Case Else
'Debug.Print InStr(1, UCase(para.Range.Text), "BOC")
'Si le paragraphe contient Bocquet, il est ignoré
If InStr(1, UCase(para.Range.Text), "BOC") <> 0 Then
'Nom de la variété de graines
xlWs.Cells(intVariete, 10) = Mid(para.Range.Text, 1, Len(para.Range.Text) - 1)
Else
intVariete = intVariete + 1
xlWs.Cells(intVariete, 1) = Mid(para.Range.Text, 1, Len(para.Range.Text) - 1)
'Titre
End If
End Select
End If
Next para
xlApp.Visible = True
End Sub |
Partager