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 61 62
| Sub BricolerDansLeTexte()
Dim WordApp As Object
Dim WordObj As Shape
Dim Phrase As String, Ok As Boolean
'Dans cet exemple l'objet Word et le dernier objet placé dans la Feuille 1
Set WordObj = Worksheets(1).Shapes(Worksheets(1).Shapes.Count)
WordObj.OLEFormat.Activate
Set WordApp = WordObj.OLEFormat.Object.Object.Application
WordApp.Visible = False
DoEvents
WordApp.Selection.HomeKey Unit:=6
Do While Not fin
With WordApp.Selection
With .Find
.Text = "["
.Execute
.Forward = True
fin = .Found = False
End With
.ExtendMode = True
If Not fin Then 'Première balise trouvée, on continue
With .Find
.Text = "]"
.Forward = True
Ok = .Execute
End With
If Ok Then
Dim FontCouleur, FontName, FontSize, FontBold, FontItalic, bold
With WordApp.Selection
Phrase = Mid(.Text, 2, Len(.Text) - 2)
With .Font
FontCouleur = .Color
FontName = .Name
FontSize = .Size
FontBold = .bold
FontItalic = .Italic
End With
End With
End If
.ExtendMode = False
.MoveRight Unit:=2, Count:=1
End If
End With
Loop
If FontBold = True Then
bold = "Gras"
Else
End If
Set WordApp = Nothing
Set WordObj = Nothing
'On quitte le document (pas indispensable mais préférable à mon avis)
Worksheets("Feuil1").Activate
Range("A1").Select
'Insertion du texte et application du style
Cells(1, 1) = Phrase
Cells(1, 1).Font.Color = FontCouleur
Cells(1, 1).Font.FontStyle = bold
Cells(1, 1).Font.Name = FontName
Cells(1, 1).Font.Size = FontSize
'etc
If Ok Then MsgBox Phrase
End Sub |
Partager