Results 1 to 11 of 11

How to create a comment box when the sheet is protected, as insert button is greyed out?

Threaded View

  1. #1
    Registered User
    Join Date
    05-14-2018
    Location
    Europe
    MS-Off Ver
    2016 64 bit
    Posts
    18

    How to create a comment box when the sheet is protected, as insert button is greyed out?

    How can I create, add, edit and remove a comment box using coding, when the sheet is in protected mode.

    Presently, in protected mode the insert comment option is greyed out not allowing me to add comments when the sheet is protected. The spreadsheets need to stay in protected mode (with only a few specific cells unlocked) as I will not be the only person using it. The 'Edit Object' boxes also need to remain unchecked when the sheets are protected.

    Can someone provide me with the correct coding as to how to do this please, and/or also specify why the below codes do not work?

    I'm using Excel 2016.

    Thank you.




    INSERT COMMENT CODE:


        Public Sub InsertComment()
            Dim sPassword As String
            Dim MyComment As String
        
            sPassword = "TestPassword"
        
            Set commentCell = ActiveCell
            MyComment = InputBox("Enter your comments", "Comments")
        
            ActiveSheet.Unprotect Password:=sPassword
            Range(commentCell.Address).AddComment
            Range(commentCell.Address).Comment.Text Text:=MyComment
            ActiveSheet.Protect Password:=sPassword
        End Sub


    EDIT, ADD, DELETE COMMENT CODE:


        Option Explicit:
        
        Sub myAdd_myEdit_myDelete_Comment()
        Dim myAdd, myEdit, myAE
        Dim MyComment As String
        Dim commentCell As Range
        Dim myCheck
        
        myAE = InputBox("If adding comment enter ""Add""" _
                          & vbCr & vbCr & _
                        "If editing comment enter ""Edit""" _
                        & vbCr & vbCr & _
                        "If Deleting comment enter ""Delete""", "Comments")
                        
        If myAE = "Add" Then
            ActiveSheet.Unprotect Password:="TestPassword"
            
            Set commentCell = ActiveCell
            MyComment = InputBox("Enter your Comment text...", "Comments")
            
            If Not ActiveCell.Comment Is Nothing Then Exit Sub
        
            Range(commentCell.Address).AddComment
            Range(commentCell.Address).Comment.Text Text:=MyComment
           
           ElseIf myAE = "Edit" Then
            MyComment = InputBox("Enter your Comment NEW text...", "Comments")
            ActiveCell.Comment.Text Text:=MyComment
                ElseIf myAE = "Delete" Then
           
            myCheck = MsgBox("Do you want to DELETE this Comment?", vbYesNo)
              If myCheck = vbNo Then
                  Exit Sub
                Else
                  ActiveCell.Comment.Delete
              End If
        
            ActiveSheet.Protect Password:="TestPassword"
        End If
        
        End Sub


    REMOVE COMMENT CODE:


        Sub Comment_Be_Gone()
          Dim rng As Range
            Set rng = ActiveCell
            If Not (rng.Comment Is Nothing) Then rng.Comment.Delete
        End Sub
        
        Sub Remove_All_Comments_From_Worksheet()
        
         Cells.ClearComments
        
        End Sub
    Last edited by Excel-7878; 05-20-2018 at 03:03 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 11-16-2012, 04:35 AM
  2. Replies: 3
    Last Post: 09-26-2012, 06:17 AM
  3. Insert cell comment on a protected sheet
    By LAF in forum Excel General
    Replies: 4
    Last Post: 07-22-2009, 05:49 AM
  4. create button greyed in macro dialogue
    By telstrareg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2008, 09:25 PM
  5. Replies: 1
    Last Post: 07-25-2006, 08:20 AM
  6. can you insert a comment into a protected worksheet?
    By TKGerdie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-18-2005, 12:05 PM
  7. Insert comment in protected worksheet
    By The Tuner in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 07:05 AM
  8. Replies: 0
    Last Post: 05-18-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1