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
| '°°° Monter les références suivantes °°°
'''Library Word
'''C:\Program Files\Microsoft Office\OFFICE11\MSWORD.OLB
'''Microsoft Word 11.0 Object Library
'''Library MSForms
'''C:\WINDOWS\system32\FM20.DLL
'''Microsoft Forms 2.0 Object Library
'°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
'### Constante à adapter ###
Const DOC_WORD = "C:\froggyaz.doc"
Const MA_FEUILLE = "test"
'###########################
Const TEXTBOX_TYPE As String = "Forms.TextBox.1"
Private Sub CommandButton1_Click()
Dim i&
Dim j&
Dim cpt&
Dim inhib As Integer
Dim myDoc As Word.Document
Dim ILS As Word.InlineShape
Dim TB() As Object 'MSForms.TextBox
Dim S As Worksheet
Set myDoc = GetObject(DOC_WORD)
For Each ILS In myDoc.InlineShapes
If ILS.OLEFormat.ClassType = TEXTBOX_TYPE Then
cpt& = cpt& + 1
ReDim Preserve TB(1 To cpt&)
Set TB(cpt&) = ILS.OLEFormat.Object
End If
Next ILS
Set S = Sheets(MA_FEUILLE)
For i& = 1 To S.[a65536].End(xlUp).Row
For j& = 1 To cpt&
If UCase("TextBox" & S.Range("A" & i& & "")) = UCase(TB(j&).Name) Then
inhib = S.Range("B" & i& & "")
TB(j&).BackColor = RGB(0, inhib / 100 * 255, 255)
Exit For
End If
Next j&
Next i&
myDoc.Save
myDoc.Parent.Quit
Set myDoc = Nothing
End Sub |
Partager