Un ami m'a demande de lui faire une petite macro dans word pour supprimer les doubles espaces dans un document Word à l'aide d'un bouton intégré dans une barre d'outil. Voici la petite macro à intégrer soit au normal.dot, soit au document. Vous en souhaitant bonne réception...
- Code: Tout sélectionner
Option Explicit
Sub Creation_bouton()
Dim cmdbar As CommandBar
Dim btn As CommandBarButton
On Error Resume Next
Application.CommandBars("Personnel").Delete
On Error GoTo 0
Set cmdbar = CommandBars.Add(Name:="Personnel", Position:=msoBarTop, temporary:=True)
Set btn = cmdbar.Controls.Add(Type:=msoControlButton)
With btn
.FaceId = 59
.Tag = "RightArrow"
.OnAction = "Suppression_Espace"
End With
cmdbar.Visible = True
End Sub
Sub Suppression_Espace()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub




