Sub Afficher_Word()
Dim Wapp As Object, Wdoc As Object, hligne, i
On Error Resume Next
Set Wapp = GetObject(, "Word.Application")
If Wapp Is Nothing Then Set Wapp = CreateObject("Word.Application")
On Error GoTo 0
Wapp.Visible = True
Set Wdoc = Wapp.Documents.Open(ThisWorkbook.Path & "\Chat.docx")
hligne = 15 'à adapter
'---1er tableau Word---
If Cbox1 <> "" Then
With Wdoc.Bookmarks("Animal").Range
.Text = LCase(Cbox1)
Wdoc.Bookmarks.Add "Animal", Wdoc.Range(.Start, .Start + Len(Cbox1))
End With
End If
If CboxFruits <> "" Then
With Wdoc.Bookmarks("Fruits").Range
.Text = LCase(CboxFruits)
Wdoc.Bookmarks.Add "Fruits", Wdoc.Range(.Start, .Start + Len(CboxFruits))
End With
End If
If TextBox1 <> "" Then
With Wdoc.Bookmarks("Activite").Range
.Text = TextBox1
Wdoc.Bookmarks.Add "Activite", Wdoc.Range(.Start, .Start + Len(TextBox1))
End With
End If
If CboxFruits = "Pommes" Then
Wdoc.Tables(1).Rows.SetHeight hligne, 2 'wdRowHeightExactly
For i = 1 To 6
Wdoc.Tables(1).Borders(i).LineStyle = 1 'wdLineStyleSingle
Next i
Else
Wdoc.Tables(1).Rows.SetHeight 0.1, 2 'wdRowHeightExactly
For i = 1 To 6
Wdoc.Tables(1).Borders(i).LineStyle = 0 'wdLineStyleNone
Next i
End If
'---3ème tableau Word---
If Cbox1 <> "" Then
With Wdoc.Bookmarks("Animal1").Range
.Text = LCase(Cbox1) & " "
Wdoc.Bookmarks.Add "Animal1", Wdoc.Range(.Start, .Start + Len(Cbox1) + 1)
End With
End If
If Cbox2 <> "" Then
With Wdoc.Bookmarks("Couleur").Range
.Text = LCase(Cbox2)
Wdoc.Bookmarks.Add "Couleur", Wdoc.Range(.Start, .Start + Len(Cbox2))
End With
End If
If Cbox1 = "Chat" And Cbox2 = "Vert clair" Then
Wdoc.Tables(3).Rows.SetHeight hligne, 2 'wdRowHeightExactly
For i = 1 To 6
Wdoc.Tables(3).Borders(i).LineStyle = 1 'wdLineStyleSingle
Next i
Else
Wdoc.Tables(3).Rows.SetHeight 0.1, 2 'wdRowHeightExactly
For i = 1 To 6
Wdoc.Tables(3).Borders(i).LineStyle = 0 'wdLineStyleNone
Next i
End If
'---4ème tableau Word---
If Cbox1 <> "" Then
With Wdoc.Bookmarks("Animal2").Range
.Text = LCase(Cbox1) & " "
Wdoc.Bookmarks.Add "Animal2", Wdoc.Range(.Start, .Start + Len(Cbox1) + 1)
End With
End If
If Cbox2 <> "" Then
With Wdoc.Bookmarks("Couleur1").Range
.Text = LCase(Cbox2)
Wdoc.Bookmarks.Add "Couleur1", Wdoc.Range(.Start, .Start + Len(Cbox2))
End With
End If
If Cbox1 = "Chat" And Cbox2 = "Vert foncé" Then
Wdoc.Tables(4).Rows.SetHeight hligne, 2 'wdRowHeightExactly
For i = 1 To 6
Wdoc.Tables(4).Borders(i).LineStyle = 1 'wdLineStyleSingle
Next i
Else
Wdoc.Tables(4).Rows.SetHeight 0.1, 2 'wdRowHeightExactly
For i = 1 To 6
Wdoc.Tables(4).Borders(i).LineStyle = 0 'wdLineStyleNone
Next i
End If
'---5ème tableau Word---
If Cbox1 <> "" Then
With Wdoc.Bookmarks("Animal3").Range
.Text = Cbox1
Wdoc.Bookmarks.Add "Animal3", Wdoc.Range(.Start, .Start + Len(Cbox1))
End With
End If
AppActivate Wapp.Caption 'facultatif, affiche Word
End Sub