Brando15

Hello,

I am programming a userform to input and edit records in a spreadsheet. I have a couple of textboxes in the form that I am using to add comment boxes to certain cells. I am trying to find a way to set the comment boxes format to automatic size within the userform's code. This way long comments will be entirely visible when the mouse hovers over the comment.

Any help or suggestions would be very helpful.

Thanks,

-Brando



Re: Visual Studio Tools for Office Programming Comments in Excel 2003

Ji Zhou – MSFT

Hi Brando,

I manage it by set the height of Comment’s Shape according to the length of your string. The following is my codes, and it works fine on my machine. Wish it can help you. If you are not clear about anything in these codes, please feel free to let me know. J

Code Snippet

Excel.Worksheet ws = this.Application.ActiveSheet as Excel.Worksheet;

Excel.Range range = ws.Cells[1, 1] as Excel.Range;

String s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalong string";

Excel.Comment comment = range.AddComment(s);

Excel.Shape shape = (Excel.Shape)comment.Shape;

int i = s.Length / 17 + 1; //By default, there's 17 character in each line of a comment

shape.Height = 4 + 10*i; //4 is the height above your comment, and 10 is the height of each line

Thanks

Ji