PC Review


Reply
Thread Tools Rate Thread

code to make a comment macro uneditable

 
 
Adam at Star Packaging
Guest
Posts: n/a
 
      3rd Apr 2009
I have the following macro set, but I would like to make the text portion of
it uneditable. Is there a code to place in the macro for this?

(Protect document will not work for us in this case)

Sub CommentAddPic()
'adds formatted comment with picture
Dim cmt As Comment
Set cmt = ActiveCell.Comment
If cmt Is Nothing Then
ActiveCell.AddComment Text:="On" & Now()
Set cmt = ActiveCell.Comment
With cmt.Shape.TextFrame.Characters.Font
.Bold = False
.ColorIndex = 0
End With
cmt.Shape.Fill.UserPicture "C:\Documents and Settings\All
Users\Documents\My Pictures\Sample Pictures\sig.jpg"
End If
End Sub

Thanks!

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      3rd Apr 2009
I am not sure what you mean by the "text portion" but if you mean you want
to protect the code itself, then in the VBE, click Tools>VBA Project
Properties>Protection and enter a password that locks out any casual
observer from the code. It cannot be accessed by a user from Excel, it can
only be accessed through the VBE with a password thereafter.


"Adam at Star Packaging" <(E-Mail Removed)>
wrote in message news:0165FC46-E3BD-4BF3-B27F-(E-Mail Removed)...
>I have the following macro set, but I would like to make the text portion
>of
> it uneditable. Is there a code to place in the macro for this?
>
> (Protect document will not work for us in this case)
>
> Sub CommentAddPic()
> 'adds formatted comment with picture
> Dim cmt As Comment
> Set cmt = ActiveCell.Comment
> If cmt Is Nothing Then
> ActiveCell.AddComment Text:="On" & Now()
> Set cmt = ActiveCell.Comment
> With cmt.Shape.TextFrame.Characters.Font
> .Bold = False
> .ColorIndex = 0
> End With
> cmt.Shape.Fill.UserPicture "C:\Documents and Settings\All
> Users\Documents\My Pictures\Sample Pictures\sig.jpg"
> End If
> End Sub
>
> Thanks!
>



 
Reply With Quote
 
Adam at Star Packaging
Guest
Posts: n/a
 
      3rd Apr 2009
Anytime a comment is made, the cell can be right-click "edit comment."

I'm wondering if there is a way to keep the Now() portion of the comment to
become uneditable.

Again, without using the protect document option.


"JLGWhiz" wrote:

> I am not sure what you mean by the "text portion" but if you mean you want
> to protect the code itself, then in the VBE, click Tools>VBA Project
> Properties>Protection and enter a password that locks out any casual
> observer from the code. It cannot be accessed by a user from Excel, it can
> only be accessed through the VBE with a password thereafter.
>
>
> "Adam at Star Packaging" <(E-Mail Removed)>
> wrote in message news:0165FC46-E3BD-4BF3-B27F-(E-Mail Removed)...
> >I have the following macro set, but I would like to make the text portion
> >of
> > it uneditable. Is there a code to place in the macro for this?
> >
> > (Protect document will not work for us in this case)
> >
> > Sub CommentAddPic()
> > 'adds formatted comment with picture
> > Dim cmt As Comment
> > Set cmt = ActiveCell.Comment
> > If cmt Is Nothing Then
> > ActiveCell.AddComment Text:="On" & Now()
> > Set cmt = ActiveCell.Comment
> > With cmt.Shape.TextFrame.Characters.Font
> > .Bold = False
> > .ColorIndex = 0
> > End With
> > cmt.Shape.Fill.UserPicture "C:\Documents and Settings\All
> > Users\Documents\My Pictures\Sample Pictures\sig.jpg"
> > End If
> > End Sub
> >
> > Thanks!
> >

>
>
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      3rd Apr 2009
Well, this is not foolproof (the user can not enable macros when the workbook is open); but, assuming that doesn't happen, this can be used to preserve existing comments...


--
Rick (MVP - Excel)


"Adam at Star Packaging" <(E-Mail Removed)> wrote in message news:2725E221-E573-4DAB-B0FB-(E-Mail Removed)...
> Anytime a comment is made, the cell can be right-click "edit comment."
>
> I'm wondering if there is a way to keep the Now() portion of the comment to
> become uneditable.
>
> Again, without using the protect document option.
>
>
> "JLGWhiz" wrote:
>
>> I am not sure what you mean by the "text portion" but if you mean you want
>> to protect the code itself, then in the VBE, click Tools>VBA Project
>> Properties>Protection and enter a password that locks out any casual
>> observer from the code. It cannot be accessed by a user from Excel, it can
>> only be accessed through the VBE with a password thereafter.
>>
>>
>> "Adam at Star Packaging" <(E-Mail Removed)>
>> wrote in message news:0165FC46-E3BD-4BF3-B27F-(E-Mail Removed)...
>> >I have the following macro set, but I would like to make the text portion
>> >of
>> > it uneditable. Is there a code to place in the macro for this?
>> >
>> > (Protect document will not work for us in this case)
>> >
>> > Sub CommentAddPic()
>> > 'adds formatted comment with picture
>> > Dim cmt As Comment
>> > Set cmt = ActiveCell.Comment
>> > If cmt Is Nothing Then
>> > ActiveCell.AddComment Text:="On" & Now()
>> > Set cmt = ActiveCell.Comment
>> > With cmt.Shape.TextFrame.Characters.Font
>> > .Bold = False
>> > .ColorIndex = 0
>> > End With
>> > cmt.Shape.Fill.UserPicture "C:\Documents and Settings\All
>> > Users\Documents\My Pictures\Sample Pictures\sig.jpg"
>> > End If
>> > End Sub
>> >
>> > Thanks!
>> >

>>
>>
>>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      3rd Apr 2009
Well, this is not foolproof (the user can not enable macros when the workbook is open); but, assuming that doesn't happen, you can do the following to preserve the existing comments. Place each section of code into the indicated location.

Put in a Module (Insert/Module from VB editor)
============================================================
Dim CellAddress As String
Dim CommentOnEntry As String

Put in Sheet module (select sheet from list on left of VB editor)
============================================================
Private Sub Worksheet_Activate()
CellAddress = ActiveCell.Address
If Not ActiveCell.Comment Is Nothing Then
CommentOnEntry = ActiveCell.Comment.Text
End If
End Sub

Private Sub Worksheet_Deactivate()
If CommentOnEntry <> "" Then
Range(CellAddress).Comment.Text CommentOnEntry
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If CommentOnEntry <> "" Then
Range(CellAddress).Comment.Text CommentOnEntry
End If
CellAddress = Target.Address
If Not ActiveCell.Comment Is Nothing Then
CommentOnEntry = Target.Comment.Text
End If
End Sub

Put in the Workbook module (ThisWorkbook from list on left of VB editor)
============================================================
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If CommentOnEntry <> "" Then
Range(CellAddress).Comment.Text CommentOnEntry
End If
End Sub

After doing that, go back to the worksheet, select a cell with a comment and edit the comment. Now, when you click into another cell, switch to another sheet or save the workbook, the original comment will be restored.

--
Rick (MVP - Excel)


"Adam at Star Packaging" <(E-Mail Removed)> wrote in message news:2725E221-E573-4DAB-B0FB-(E-Mail Removed)...
> Anytime a comment is made, the cell can be right-click "edit comment."
>
> I'm wondering if there is a way to keep the Now() portion of the comment to
> become uneditable.
>
> Again, without using the protect document option.
>
>
> "JLGWhiz" wrote:
>
>> I am not sure what you mean by the "text portion" but if you mean you want
>> to protect the code itself, then in the VBE, click Tools>VBA Project
>> Properties>Protection and enter a password that locks out any casual
>> observer from the code. It cannot be accessed by a user from Excel, it can
>> only be accessed through the VBE with a password thereafter.
>>
>>
>> "Adam at Star Packaging" <(E-Mail Removed)>
>> wrote in message news:0165FC46-E3BD-4BF3-B27F-(E-Mail Removed)...
>> >I have the following macro set, but I would like to make the text portion
>> >of
>> > it uneditable. Is there a code to place in the macro for this?
>> >
>> > (Protect document will not work for us in this case)
>> >
>> > Sub CommentAddPic()
>> > 'adds formatted comment with picture
>> > Dim cmt As Comment
>> > Set cmt = ActiveCell.Comment
>> > If cmt Is Nothing Then
>> > ActiveCell.AddComment Text:="On" & Now()
>> > Set cmt = ActiveCell.Comment
>> > With cmt.Shape.TextFrame.Characters.Font
>> > .Bold = False
>> > .ColorIndex = 0
>> > End With
>> > cmt.Shape.Fill.UserPicture "C:\Documents and Settings\All
>> > Users\Documents\My Pictures\Sample Pictures\sig.jpg"
>> > End If
>> > End Sub
>> >
>> > Thanks!
>> >

>>
>>
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
comment: make sure your code files are where you think they are vbDavidC Microsoft VB .NET 2 9th Apr 2009 11:33 PM
Edit Comment erases part of screen; comment uneditable Charles Blaquière Microsoft Excel Discussion 0 10th Sep 2008 08:31 PM
Comment becomes uneditable, cell flashes Charles Blaquière Microsoft Excel New Users 3 9th Oct 2007 04:33 AM
Make column uneditable bharath_pepala Microsoft Excel Discussion 3 20th Jan 2006 08:45 PM
make combobox uneditable cparsons Microsoft Excel Misc 2 9th Aug 2004 01:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 AM.