Scaling an Excel worksheet
December 9th, 2009
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.
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.
