View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1554_] Rick Rothstein \(MVP - VB\)[_1554_] is offline
external usenet poster
 
Posts: 1
Default Working with Cell Comments - VBA


"Peter T" <peter_t@discussions wrote in message
...
As for vbNewLine compared to vbLf... like many Windows
objects, it doesn't seem to matter which you use...


For me (version?) it's the difference between seeing the little square or
not at the end of the line (in a Comment). IOW it's the vbCr/chr(13) that
produces that little square.

Similarly for cells -
ActiveCell.Value = "A" & vbNewLine & "B" ' little square
ActiveCell.Offset(, 1).Value = "A" & vbLf & "B" ' no square

Regards,
Peter T

"Rick Rothstein (MVP - VB)" wrote in
message ...
TextFrame.AutoSize ... I completely missed that one (I knew it something
like that had to exist, I just couldn't find it).

As for vbNewLine (which I like using over its more familiar form, vbCrLf,
because of its descriptive name) compared to vbLf... like many Windows
objects, it doesn't seem to matter which you use... if you use vbNewLine,
then both the carriage return and line feed are placed in the text
string;
if you use vbLf, then just the line feed is placed in the text string;
but
either way, the Comment box seems to know how to display them each
correctly.

Rick


"Peter T" <peter_t@discussions wrote in message
...
For #2, to autosize
.Comment.Shape.TextFrame.AutoSize = True

I think better to change vbNewLine to vbLf

Regards,
Peter T

"Rick Rothstein (MVP - VB)" wrote

in
message ...
This code snippet will show you how to handle questions #1 and #3 (I'm
not
sure how to do #2)....

Sub Test()
Dim OldComment As String
With Worksheets("Sheet1").Range("C5")
OldComment = .Comment.Text
.Comment.Delete
.AddComment OldComment & vbNewLine & "I'm on the next line."
End With
End Sub

Rick


"Mr B" wrote in message
...
Thanks to peoplehere, I have a script that's working great for me
but
it
involves settings comments for cells. I want to to some more

advanced
things
with the Comments box but don't know how.

1) How can I add a Line Return in the comments box when adding text

to
the
box in the VBA script? I tried using vbCr and vbCrLn which work but

it
puts
a square symbol in the comments instead of just a lien return. I'm
assuming
there's some other coed I should use?

2) Is there a way to set the size of the comments box so it's only

big
enough ti display whatever text is actually in there? Each cell
will
have
different amounts of text and I don't want tons of blank space if
there's
just one line of text and don't want it cut off if there's 5
lines...

3) Can I concatenate comments if comments already exist?