Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to judge some cell that had been added comments?

Hi,
I write a macro. It add comments into some specific cells. After added
comments, I want to update comments by AddComment() method. It appear error.
So I must judge the cells whether had been added comments. Would you tell me
which methods are able to implement it? Thank you very much!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default How to judge some cell that had been added comments?

Hi Terry,
If you try do AddComment when one already exists I think you first have
to delete the existing comment eg
ActiveSheetRange("A1").Comment.Delete.

Alternativing you can edit the comment like this:
ActiveSheetRange("A1").Comment.Shape.TextFrame.Cha racters.Text = "Blah
Blah Blah"

Also, when code is trying to do something to a comment that doesn't
exist an error results.
This error can be overcome using:

On Error Resume Next
ActiveSheetRange("A1").Comment.Shape.TextFrame.Cha racters.Text = "Blah
Blah Blah"
On Error Goto 0 'that's a zero, not an O

If A1 on Active Sheet doesn't have a comment the error message is
avoided. If A1 does have a comment it is changed to "Blah Blah Blah"

Does this help?

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default How to judge some cell that had been added comments?

Hi Terry,
sorry, my code samples all have the "." missing between ActiveSheet
and Range.

To hopefully clarify my last reply:

1) to use AddComment to edit ActiveSheet's A1 comment when A1 may or
may not already have a comment use:

On Error Resume Next
With ActiveSheet.Range("A1")
.Comment.Delete
.AddComment "Blah Blah Blah"
End With
On Error GoTo 0

2) to edit Active Sheet's A1 comment only when A1 already has a comment
use:

On Error Resume Next
ActiveSheet.Range("A1").Comment.Shape.TextFrame.Ch aracters.Text = "Blah
Blah Blah"
On Error GoTo 0

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default How to judge some cell that had been added comments?

Hi terry,

Try this,

Sub Test()
Dim rng As Range
Dim cmttext As String
cmttext = "Insert New comment text here."
Set rng = ActiveCell

If Not rng.Comment Is Nothing Then
If MsgBox("Below Comment is already present in the active
cell.Do You want to overwrite it." _
& vbNewLine & rng.Comment.Text, vbYesNo, "Insert Comment") =
vbYes Then
rng.Comment.Delete
rng.AddComment cmttext
End If
Else
rng.AddComment cmttext
End If
End Sub


Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/
http://in.geocities.com/shahshaileshs/
(Excel Add-ins Page)

*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
jtp jtp is offline
external usenet poster
 
Posts: 1
Default How to judge some cell that had been added comments?


Terry, it sounds like you want to add text to a comment that is alread
there. Taking what Shah wrote and modifying it to update rather tha
overwrite, it would look like this.

Sub Test()
Dim rng As Range
Dim cmttext As String, oldtext as string

cmttext = "Insert New comment text here."
Set rng = ActiveCell

If Not rng.Comment Is Nothing Then
If MsgBox("Below Comment is already present in the active
cell.Do You want to update it." _
& vbNewLine & rng.Comment.Text, vbYesNo, "Update Comment") =
vbYes Then
oldtext = rng.comment.text
rng.Comment.Delete
rng.AddComment oldtext & chr(13) & cmttext
End If
Else
rng.AddComment cmttext
End If
End Sub

Otherwise if you just want to overwrite it, Shah's procedure i
perfect.

Jaso

--
jt
-----------------------------------------------------------------------
jtp's Profile: http://www.excelforum.com/member.php...fo&userid=2113
View this thread: http://www.excelforum.com/showthread.php?threadid=49599

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel and searching for a string in a cell where comments have been added sammy[_2_] Excel Discussion (Misc queries) 1 August 7th 11 12:23 PM
Allow comments to be added to protected worksheet? - Excel 2007 sue@solotel New Users to Excel 1 November 5th 09 12:21 AM
Delete added comments Doman Excel Discussion (Misc queries) 3 July 18th 06 12:29 PM
How to judge wheter an object is existing or not lvcha.gouqizi Excel Programming 6 November 1st 05 09:32 PM
Searching within comments added to cells red6000 Excel Programming 2 July 22nd 05 01:28 AM


All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"