Excel -Change size of Comment Box Programatically using C# VSTO Code


C# Excel VSTO - Change size of Comment Box programmatically using Code

How to change the size of excel comment box using C# VSTO code



Adding comments for excel cell is very easy & but ever thought of resizing the the comment box. Today we will see how can you change the size of comment box programmatically using C# code. This code can be used in VSTO for Excel.


How to add comment box to excel manually

1. Select the cell or range for which you need to add the comment. Now right click & select the 'insert comment' option.
2. Enter the text which you would like to see as comment & press enter
3. Comment will be seen with default size.
4. To Resize it, right click & select 'Edit Comment'.
5. Expand & adjust comment box with your mouse.


algorithm to add comment box to excel & resize comment Box

1. select Range  e.g. Range myRange
2. add a comment using  myRange.AddComment()
3. myRange .Comment.Shape.ScaleHeight()

Range myRange is your range for which you need to insert comment.  If you just want to insert a comment simple use following code.

myRange.AddComment("This is name of my blog");
If you want to add commeny & resize the comment box you nee to use shape property.
myRange.AddComment("This is name of my blog with Resized comment box");

/* set the Height & width variables & */ 

float val1 = 5.001f;
float val2 = 3.001f;

/* set the Height & width variables & */ 


myRange.Comment.Shape.ScaleHeight(val1, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft);



myRange.Comment.Shape.ScaleWidth(val2, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft);


C# Excel VSTO - Change size of Comment Box programmatically using Code

How to change the size of excel comment box using C# VSTO code



Adding comments for excel cell is very easy & but ever thought of resizing the the comment box. Today we will see how can you change the size of comment box programmatically using C# code. This code can be used in VSTO for Excel.


How to add comment box to excel manually

1. Select the cell or range for which you need to add the comment. Now right click & select the 'insert comment' option.
2. Enter the text which you would like to see as comment & press enter
3. Comment will be seen with default size.
4. To Resize it, right click & select 'Edit Comment'.
5. Expand & adjust comment box with your mouse.


algorithm to add comment box to excel & resize comment Box

1. select Range  e.g. Range myRange
2. add a comment using  myRange.AddComment()
3. myRange .Comment.Shape.ScaleHeight()

Range myRange is your range for which you need to insert comment.  If you just want to insert a comment simple use following code.

myRange.AddComment("This is name of my blog");
If you want to add commeny & resize the comment box you nee to use shape property.
myRange.AddComment("This is name of my blog with Resized comment box");

/* set the Height & width variables & */ 

float val1 = 5.001f;
float val2 = 3.001f;

/* set the Height & width variables & */ 


myRange.Comment.Shape.ScaleHeight(val1, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft);



myRange.Comment.Shape.ScaleWidth(val2, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoScaleFrom.msoScaleFromTopLeft);

Was that useful? Why not share it?

By: