Home > Technology > Scaling an Excel worksheet

Scaling an Excel worksheet

December 9th, 2009 Leave a comment Go to comments

Description:
WinForm controls placed in a worksheet while it is not at 100% will be positioned incorrectly. Here’s a simple workaround to change the zoom to 100% then revert to the previous setting.

Code:

int lastZoom = 100;
int.TryParse(<your worksheet>.Application.ActiveWindow.Zoom.ToString(), out lastZoom);
if ( lastZoom != 100 )
	<your worksheet>.Application.ActiveWindow.Zoom = 100;
// do something interesting
if ( lastZoom != 100 )
	<your worksheet>.Application.ActiveWindow.Zoom = lastZoom;

Notes:
Don’t forget to use “Application.ScreenUpdating = false;” to avoid lag and screen flutter.

Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.