Link to home
Start Free TrialLog in
Avatar of tcalbaz
tcalbazFlag for United States of America

asked on

Excel 2002: How do I use VBA to set the area size of my chart to 600 width 300 height?

I just upgraded my Office 97 to 2002.  I can't seem to set the absolute width and height of my chart to a 600 pixel width and a 300 pixel height on the activesheet.  Does anybody have a technique for this?

Many thanks,
Avatar of sebastienm
sebastienm

As for your previous question:
several ways...
1. you can go through the Shape object:
        ActiveSheet.Shapes("Chart 1").width = 600
        ActiveSheet.Shapes("Chart 1").height = 300
2. or the ChartObjects()
     activesheet.chartobjects(1).width= 600
     activesheet.chartobjects(1).height= 300

however, the units are in  points, not pixels.
You can transform points to pixels, by using the
   PointsToScreenPixelsX
   PointsToScreenPixelsY
functions of the Window object, eg:
       ActiveSheet.Shapes("Chart 1").Width = 600 / ActiveWindow.PointsToScreenPixelsX(1)
    ActiveSheet.Shapes("Chart 1").Top = 300 / ActiveWindow.PointsToScreenPixelsY(1)

or by applying the function of the Application.Windows(1).

Just make sure a window is there when you run it.

Regards,
Sebastien
ASKER CERTIFIED SOLUTION
Avatar of sebastienm
sebastienm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tcalbaz

ASKER

Well Done!
Thank You Sebastienm!

Ted
Thank you for the points, Ted.

Regards,
Sebastien