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
| Sub test()
' http://www.cpearson.com/excel/vbe.aspx
' reference : Microsoft Visual Basic for Applications Extensibility 5.3
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim wdDoc As Document
Dim i As Long
' bleu docaposte = RGB(65, 124, 255), en HEXA = #417CFF, en Long = 16743489
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=1
NEW_COULEUR = hexa_color(InputBox("Code hexa de la couleur (ex : #417CFF)", "Nouvelle couleur", "#C92CB2"))
Selection.Find.ClearFormatting
Selection.Find.Font.Color = LAST_COULEUR
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = NEW_COULEUR
Selection.Find.Execute Replace:=wdReplaceAll
a = "Public Const LAST_COULEUR As Long = " & LAST_COULEUR
b = "Public Const LAST_COULEUR As Long = " & NEW_COULEUR
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Set VBProj = ActiveDocument.VBProject
Set VBComp = VBProj.VBComponents("Module1") ' !!! attention au nom du module standard !!!
Set CodeMod = VBComp.CodeModule
Set wdDoc = ActiveDocument
With CodeMod ' dans le module
For i = 1 To .CountOfLines ' on cherche de la 1ère à la dernière ligne
If .Lines(i, 1) = "" & a & "" Then ' ceci : Public Const LAST_COULEUR As Long = 16743489
.ReplaceLine i, "" & b & "" ' pour le remplacer par ceci : Public Const LAST_COULEUR As Long = 11676873
End If
Next i
End With
End Sub |
Partager