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
| Private Sub insertcomment_Click()
Dim oApp As Excel.Application
Dim oWkb As Excel.Workbook
Dim oWSht As Excel.Worksheet
Dim i As Long
Dim coment As String
Dim dat As String
coment = Me.coment.Value
dat = Format(Me.Datecomment, "dd.mm.yyyy")
Set oApp = CreateObject("excel.application")
Set oWkb = oApp.Workbooks.Open("D:\test.xlsm")
Set oWSht = oWkb.Worksheets("suivi")
i = 2
' ActiveSheet.UsedRange.Rows.Count : nb lignes utilisées dans une feuille
Do While i <= oWSht.UsedRange.Rows.Count
If oWSht.Range("A" & i).Value = Me.NIMMA Then
' on fait ici le traitement souhaité, par exemple sur la cellule à modifier (1 pour A, 2 pour B,..., 6 pour F)avec vérification si commentaire déjà existant
oWSht.Cells(i, 6).comment.Visible = True
If Len(Nz(oWSht.Cells(i, 6).comment.Text)) > 0 Then
' le commentaire de la case comporte déjà une valeur
oWSht.Cells(i, 6).comment.Text Text:=oWSht.Cells(i, 6).comment.Text & vbLf & dat & coment
Else
oWSht.Cells(i, 6).comment.Text Text:=oWSht.Cells(i, 6).dat & coment
End If
Exit Do ' on sort de la boucle
Else
i = i + 1
End If
Loop
Set oWSht = Nothing
oWkb.Close
Set oWkb = Nothing
Set oApp = Nothing
End Sub |