How to fix chart size regardless of zoom?

Kelvin Stott

Active Member
Joined
Oct 26, 2010
Messages
338
Hello, I hope somebody can help:

I've written some VBA code to create a chartobject and then save it as a GIF file, which is then loaded into a user form. This all works well and the image looks perfect - however, if I change the zoom of the active worksheet before running the code, the size and resolution of the chart object and resulting image file are changed, so that it looks really bad when loaded into the user form.

Is there any way to fix the size and resolution of the chart object and image, regardless of the current zoom, so that I get consistent & predictable results?

I also tried creating the chart as a chartsheet (rather than a chart object on the current worksheet), but that has its own problems as all the text and image proportions are messed up.

Please help, thanks!
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Got it, thanks! Will report back soon ... :)
It's strange, but even when I reset the zoom just before and after export, I still see the sheet zoom in/out, and even see the temporary chart object in the background for a split second. Maybe it's the export that's too slow. :(

I'll try the window method now...
 
Upvote 0
It's strange, but even when I reset the zoom just before and after export, I still see the sheet zoom in/out, and even see the temporary chart object in the background for a split second. Maybe it's the export that's too slow. :(

I'll try the window method now...

Does that happen even when turning the screen updating off ?

Code:
Application.ScreenUpdating = False

[COLOR=SeaGreen]' Create the chart here...[/COLOR]

ActiveWindow.Zoom = 100

[COLOR=SeaGreen]'Export chart here...[/COLOR]

[COLOR=SeaGreen]'Restore initial Zoom here ...[/COLOR]

Application.ScreenUpdating = True
 
Upvote 0
Does that happen even when turning the screen updating off ?

Code:
Application.ScreenUpdating = False

[COLOR=SeaGreen]' Create the chart here...[/COLOR]

ActiveWindow.Zoom = 100

[COLOR=SeaGreen]'Export chart here...[/COLOR]

[COLOR=SeaGreen]'Restore initial Zoom here ...[/COLOR]

Application.ScreenUpdating = True
Actually, with screenupdating off I don't see the temporary zoom reset (which is good), but I do see the temporary chartobject created in the background (not good).
 
Upvote 0
Actually, with screenupdating off I don't see the temporary zoom reset (which is good), but I do see the temporary chartobject created in the background (not good).

Yes I missed that

Place Application.ScreenUpdating = False AFTER creating the chart.
 
Upvote 0
Yes I missed that

Place Application.ScreenUpdating = False AFTER creating the chart.
This works perfectly now, thank you:

Code:
    Call CreateDChart 'creates chart object
    
    Application.ScreenUpdating = False 'turns off screen updating
    ChartScale = ActiveWindow.Zoom 'stores current zoom
    ActiveWindow.Zoom = 100 'resets zoom to 100%
    TempChart = ThisWorkbook.Path & "\tempchart.bmp"
    DChart.Export TempChart 'exports chart image
    ActiveWindow.Zoom = ChartScale 'resets zoom to original
    DChart.Parent.Delete 'deletes chart object
    Application.ScreenUpdating = True 'turns back on screen updating
    DControl.ChartImage.Picture = LoadPicture(TempChart) 'loads saved image into userform
    Kill TempChart 'removes temp chart file
    
    DControl.Show 'shows user form

PS. I don't seem to have the option to create floating chart window with right-click chart. Is this normal? I'm on Excel 2007, updated to 2010.
 
Upvote 0
This works perfectly now, thank you:

Code:
    Call CreateDChart 'creates chart object
    
    Application.ScreenUpdating = False 'turns off screen updating
    ChartScale = ActiveWindow.Zoom 'stores current zoom
    ActiveWindow.Zoom = 100 'resets zoom to 100%
    TempChart = ThisWorkbook.Path & "\tempchart.bmp"
    DChart.Export TempChart 'exports chart image
    ActiveWindow.Zoom = ChartScale 'resets zoom to original
    DChart.Parent.Delete 'deletes chart object
    Application.ScreenUpdating = True 'turns back on screen updating
    DControl.ChartImage.Picture = LoadPicture(TempChart) 'loads saved image into userform
    Kill TempChart 'removes temp chart file
    
    DControl.Show 'shows user form
PS. I don't seem to have the option to create floating chart window with right-click chart. Is this normal? I'm on Excel 2007, updated to 2010.

Glad it is now working for you.

I can't find that option either. I am sure I had it on excel 2003 and I have used it before. hope someone can pop in and tell us where that option is in excel 2007/2010.
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top