我设置了一个可以找到图表对象级别的代码,并且从那里我想操纵大小,字体等等。但是,我遇到的问题是宽高比是锁定,无法移动。 使用shaperange.lockaspectratio = msofalse。在本地人中,它变为False,但是当改变高度和宽度时,它仍然会随着锁定比率而变化。在excel中查看图表本身的属性,它仍然锁定在比率上。 仅供参考,当我尝试切换打印对象或锁定时,这确实有效。
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
答案 0 :(得分:0)
它没有你做过的那么复杂。如果用户选择了图表元素,那么您将拥有一个活动图表。图表对象是此图表的父级。
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