In Excel VBA how can I enable comments on a protected sheet but still protect form controls

2.2k views Asked by At

I have a protected Excel sheet. It has form controls and I have assigned macros to them. I can enable comments on this sheet by using

.Protect DrawingObjects:=False

but this also allows any form controls to be deleted.

I could change the form controls to activeX controls but this would prevent Mac users using it.

Is there a way of enabling comments but protecting the form controls?

1

There are 1 answers

1
Vityata On

Is there a way of enabling comments but protecting the form controls?

Not that I know of. But you may come up with a workaround :) Like this:

  • build a form, that has a text box and a button. Call the form with a shortcut, it would be easier;
  • select the cell you want to insert a comment to and call the form;
  • write the comment inside the form and press the button;

Something like this may be put in the code of the form. commentCell is the selected cell. Probably some check how many cells are selected can be added as well:

ActiveSheet.Unprotect Password:=sPassword
Range(commentCell.Address).AddComment
Range(commentCell.Address).Comment.Text Text:=MyComment
ActiveSheet.Protect Password:=sPassword