Hi,
I have many graphs (60+) and I have realised that, for whatever reason, some of the plot areas do not match in size despite the fact that the charts themselves have identical proportions.
Is there any way to fairly quickly fix this? I pasted the charts directly into Word 2007 (i.e. so they are editable), but this was a while ago and they do not match the original ones anymore so I will need to edit them in Word.
Any ideas?
Thanks,
SB
It doesn't need to be the fastest method possible, I would rather be able to achieve uniform dimension graphs than not at all! Unfortuantely I don't think I can use templates since the content of the graphs vary quite a lot.
Thanks,
SB
Do the charts have the same x and y axis labelling and how about the legend text?
The plot area will be adjusted automatically to allow for variations in the size/amount of text.
To force the sizing of the plotarea you would need code to loop through and adjust it's width/height/top/left.
The code to loop and change is straight forward. What is not is what values to use. How do you know which dimensions should be used on all the charts?
Thanks for the reply Andy. Almost all the charts have different x and y labels, also the legend position and contents varies considerably. I think I must have manually edited some of the plot areas at some point because they do not necessaraly match for otherwise identical charts. e.g:
Example.
These two empty graphs have the same dimensions when you select them, but the plot areas do not match.
There is no exact answer as to what the plot area dimensions should be, but the outside dimensions are 7.5cm by 15.92cm. So essentially they just need to be uniform and fill most of the width of one sheet of A4 paper (15.92cm + 2x2.54cm margins) and most of the 7.5cm chart height. How would I go about writing the code?
Thanks,
SB
Last edited by Silverbrook; 09-01-2009 at 09:22 AM.
are the charts in excel or word.
Can you post a file rather than a image.
This is a cheap and cheerful fix
Code:Sub X() Dim objInLine As InlineShape Dim chtTemp As Chart Dim shpTemp As Shape For Each objInLine In ActiveDocument.InlineShapes If objInLine.HasChart Then Set chtTemp = objInLine.Chart With chtTemp.PlotArea .Width = chtTemp.ChartArea.Width * 0.8 .Left = chtTemp.ChartArea.Width * 0.1 .Height = chtTemp.ChartArea.Height * 0.8 .Top = chtTemp.ChartArea.Height * 0.1 End With End If Next End Sub
Thanks for that Andy, your help is much appreciated. It works well, though I had trouble with one or two for some reason. Is there any way to make it so that it just resizes the currently selected graph?
Last edited by shg; 09-03-2009 at 02:36 PM. Reason: deleted spurious quote
I can not get at the chart object via the Selection object.
Nor can I identify what the selected item is called.
If the code is missing some charts it maybe because they are in the shapes collection rather the InLineShapes collection.
Thanks Andy. I suppose I could open a new word document and transfer the charts I want resizing and run the macro on those and then transfer them back. It certainly beats doing it manually with the ruler guides!!
Last edited by shg; 09-03-2009 at 02:37 PM. Reason: deleted spurious quote
I took a break and had another bash.
Try this on a selected chart
Code:Sub X() Dim objInLine As InlineShape Dim chtTemp As Chart Set objInLine = ActiveWindow.Selection.InlineShapes(1) If Not objInLine Is Nothing Then If objInLine.HasChart Then Set chtTemp = objInLine.Chart With chtTemp.PlotArea .Width = chtTemp.ChartArea.Width * 0.8 .Left = chtTemp.ChartArea.Width * 0.1 .Height = chtTemp.ChartArea.Height * 0.8 .Top = chtTemp.ChartArea.Height * 0.1 End With End If End If End Sub
Works perfectly, thanks! I figured out why a couple of them didn't resize 'correctly', it was because I had forgotten to change the font size of the y-axis to the same as the others, it made the end result slightly different but I have changed that now. Cheers Andy, the help has been massively appreciated!
Last edited by shg; 09-03-2009 at 02:37 PM. Reason: deleted spurious quote
I've just had another thought (sorry!!) is there a way to modify the code so that it will position a legend in a particular place? Also would it be possible with horizontal/vertical axes titles?
Silverbrook, kindly don't quote whole posts. It's just clutter.
Thanks.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
You just need to add the code to control the right part of the charts object model.
Code:Sub X() Dim objInLine As InlineShape Dim chtTemp As Chart Set objInLine = ActiveWindow.Selection.InlineShapes(1) If Not objInLine Is Nothing Then If objInLine.HasChart Then Set chtTemp = objInLine.Chart With chtTemp.PlotArea .Width = chtTemp.ChartArea.Width * 0.8 .Left = chtTemp.ChartArea.Width * 0.1 .Height = chtTemp.ChartArea.Height * 0.8 .Top = chtTemp.ChartArea.Height * 0.1 End With If chtTemp.HasLegend Then With chtTemp.Legend .Left = 10 .Top = 10 .Width = 50 .Height = 50 End With End If ' X axis If chtTemp.Axes(1, 1).HasTitle Then chtTemp.Axes(1, 1).AxisTitle.Left = chtTemp.PlotArea.InsideLeft End If ' Y axis If chtTemp.Axes(2, 1).HasTitle Then chtTemp.Axes(2, 1).AxisTitle.Top = chtTemp.PlotArea.InsideTop End If End If End If End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks