We help IT Professionals succeed at work.

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


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!
Watch Question

Try this:


Open in new window


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


...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-

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