?
Solved

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

Posted on 2003-03-31
4
Medium Priority
?
441 Views
Last Modified: 2008-03-10
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,
0
Comment
Question by:tcalbaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 16

Expert Comment

by:sebastienm
ID: 8240097
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
0
 
LVL 16

Accepted Solution

by:
sebastienm earned 1000 total points
ID: 8240147
ooops , i made a mistake above.
(also, it seems like the function behave weird with small number like 1),. so:

    ActiveSheet.Shapes("Chart 1").Width = 600 / ActiveWindow.PointsToScreenPixelsX(1000) * 1000
    ActiveSheet.Shapes("Chart 1").Height = 300 / ActiveWindow.PointsToScreenPixelsY(1000) * 1000

Sebastien
0
 
LVL 1

Author Comment

by:tcalbaz
ID: 8240678
Well Done!
Thank You Sebastienm!

Ted
0
 
LVL 16

Expert Comment

by:sebastienm
ID: 8240703
Thank you for the points, Ted.

Regards,
Sebastien
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
New style of hardware planning for Microsoft Exchange server.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question