View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Comment Import

Another way is to just use the cells with comments:

Option Explicit
Sub testme()
Dim myCell As Range
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("c:c").Cells.SpecialCells(xlCellTypeComment s)
On Error GoTo 0

If myRng Is Nothing Then
'do nothing--no comments
Else
For Each myCell In myRng.Cells
myCell.Offset(0, 5).Value = myCell.Comment.Text
Next myCell
End If
End With

End Sub

Or you could go through the comment collection:

Sub testme02()

Dim myComment As Comment

With Worksheets("sheet1")
For Each myComment In .Comments
If myComment.Parent.Column = 3 Then
myComment.Parent.Offset(0, 5).Value = myComment.Text
End If
Next myComment
End With

End Sub


"Ömür Ölmez" wrote:

Hello
About this topic, an idea comes to my mind :
I will create an Excel VBA.
In an event, I'll add some code like this :
dim n as integer
for n=1 to LastRowNumber
Worksheets("Sheet1").Cells(n, 8).Value = _
Worksheets("Sheet1").Cells(n, 3).Comment.Text
next
What I want to do is retrieving comments into new cells. So, I can
easily import them by using SQL's tools.
But I have some problems about this method :
* How can I check if there is a comment in a specific cell. I want
to do this because, Error 91 occurs if there is no comment in the cell when
I try to retrieve it.
* How can I use the application/code on some other excel documents.
I wonder this because as I know, the VBA code is inserted directly into
working .xls file.

By the way, the Mark's code did not run :
strComment = Sheets(1).Cells(5, 3).Comment.Text
I use this code instead of Mark's :
Worksheets("Sheet1").Cells(n, 3).Comment.Text

Thank You For Your Helps
Omur Olmez


--

Dave Peterson