简体   繁体   中英

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

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?

thanks

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM