Reputation: 1
I'm setting up a code that will find the chart object level and from there I want to manipulate size, font, etc, etc. However, I'm running into the problem that the aspect ratio is locked and can't get it moving. Using the shaperange.lockaspectratio=msofalse . In the locals it changes to False, but when changing height and width it still changes with lock ratio. Looking at the properties on the chart itself in excel, it's also still locked on ratio. FYI, when I try toggle of print object or locked, that does work.
Sub chart()
Set sc = Selection
'the user selected something, but may be chart area or plot area. So searching for the Chartobject
Dim SelectionArray(10)
Set xx = sc
For x = 1 To 10
SelectionArray(x) = TypeName(xx)
Set xx = xx.Parent
If InStr(LCase(SelectionArray(x)), "chart") Then chartfound = True 'so at least a chart found
Next x
If chartfound = True Then ' to check that a chart is selected (and not other object)
For x = 1 To 10 'finding the chartobject layer
If SelectionArray(x) = "ChartObject" Then p = x
Next x
Set xx = sc
For x = 1 To p - 1
Set xx = xx.Parent
Next x
Set sc = xx: Set xx = Nothing 'the SC is now the chart object (so to start from the same basis.
sc.ShapeRange.LockAspectRatio = msoFalse
sc.Height = 250
sc.Width = 250
End If
End Sub
Upvotes: 0
Views: 1158
Reputation: 6063
It's not as complicated as you've made it. If the user has selected a chart element, then you have an active chart. The chart object is the parent of this chart.
Sub ResizeChart()
Dim chob As ChartObject
If Not ActiveChart Is Nothing Then
Set chob = ActiveChart.Parent
With chob
chob.Parent.Shapes(chob.Name).LockAspectRatio = msoFalse
.Height = 250
.Width = 250
End With
End If
End Sub
Upvotes: 0