We help IT Professionals succeed at work.

How to use Powershell to insert a Comment into Excel cell??

Folks,

How does one go about inserting a comment into a cell in Excel using POWERSHELL?

Basically, I want to modify a cell so that I can add the comment property to it...

[I'm working on an audit form, and I want a short version of the error, and then the ability to however over the red triagle in the corner of the cell to display the full error...]

My code for selecting a cell looks like this:

$CurrentSheet.Cells.Item($ServerRow+1,$ServerCol) = $string

How do I add a comment, insert it into the cell in question, and make it visable?

Thanks all!
Comment
Watch Question

Try this:

$CurrentSheet.Cells.Item($ServerRow+1,$ServerCol).Addcomment("comment")

Open in new window

Author

Commented:
I tried it using a String, and it blew up in my face:

$CurrentSheet.Cells.Item($ServerRow+1,$ServerCol).Addcomment($SrvAppErrors[1].message)

...then I noted that you can't rewrite a comment over another comment.  ...and it works like a champ.

Maybe I can get you to help me with this:

How do I resize the comment box on the fly?  -grin-

GB
Sorry for little misconception. Try inserting [void] at begin:

[void] $CurrentSheet.Cells.Item($ServerRow+1,$ServerCol).Addcomment("comment")
[void] $CurrentSheet.Cells.Item($ServerRow+1,$ServerCol).Comment.Text("New comment")

Open in new window