Bonjour à tous,
Je programme depuis peu en VBA pour Excel et je rencontre un problème auquel je ne trouve pas de solution.
Je dois construire un fichier qui va valider des données, via macro, et que je dois fournir à des clients. Afin d'éviter toute mauvaise manipulation de la part du client, je dois verrouiller certaines cellules.
Le problème est qu'après avoir protégé la feuille excel, quand la macro essaye d'insérer un commentaire, j'ai une erreur 1004 "Cell is protected ... blabalbla"
Ci-dessous, la fonction qui foire et ci-joint, le fichier xls de test.
Ca fait deux jours que je cherche une solution et toujours rien (d'habitude Google m'est plus utile que ça)
Donc, pouvez-vous m'aider? Ca me ferait grand plaisir ;-)
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 /*********************************************************/ Sub Highlight_Cell() Dim c As Comment Dim ws As Worksheet Dim i As Integer, j As Integer i = 3 j = 8 Set ws = Application.Sheets(1) ' highlight empty cell in red ws.Cells(i, j).Interior.Color = RGB(255, 170, 170) ws.Cells(i, j).Font.Color = RGB(255, 0, 0) ' unlock the cell 'If ws.Cells(i, j).Locked = True Then ' ws.Cells(i, j).Locked = False 'End If If ws.Cells(i, j).Comment Is Nothing Then Set c = ws.Cells(i, j).AddComment Else Set c = ws.Cells(i, j).Comment End If c.Visible = True c.Text "- Test test" c.Shape.TextFrame.AutoSize = True c.Shape.Shadow.Transparency = 0.5 c.Shape.Top = c.Parent.Offset(-2, 0).Top c.Shape.Left = c.Parent.Offset(0, 2).Left - 30 ' lock the cell 'ws.Cells(i, j).Locked = False End Sub
Partager