我有一张Excel工作表,其中使用VBA创建了一个图表。问题是生成图表后我将其形状设置为内置的Shape样式。但是当我执行以下代码时,没有任何反应。
ActiveSheet.Shapes("AdoptChart").Select
ActiveSheet.ChartObjects("AdoptChart").Activate
ActiveSheet.Shapes("AdoptChart").ShapeStyle = msoShapeStylePreset22
当执行此行ActiveSheet.Shapes("AdoptChart").ShapeStyle = msoShapeStylePreset22
时,.ShapeStyle
属性不会更新,即在此行之前为0,执行此行后它仍为0.
这是我通过录制宏并手动设置图表形状样式得到的代码。
我正在使用Excel 2010,但Excel文件是2003文件(我在兼容模式下运行它。)
编辑:这是我手动选择形状后获得的宏。
Sub shape()
'
' shape Macro
'
'
ActiveSheet.Shapes("AdoptChart").ShapeStyle = msoShapeStylePreset22
Range("I7").Select
End Sub
答案 0 :(得分:0)
根据我的评论,我建议您为2010年以兼容模式打开的新Excel 2003工作簿录制宏。 So you can utilize the 2010 Ribbon as shown in this reference.但是,了解您打算使用这些图表的Excel版本非常重要。它将在2010年或2003年......在2007年增加ShapeStyle
......
2
。在“格式”选项卡上,执行以下操作之一:在“当前选择”组中,单击“格式选择”,然后在“格式”对话框中,选择所需的格式选项。在“形状样式”组中,单击“更多”按钮“按钮”图像,然后选择一种样式。
Excel功能区图片:
在“形状样式”组中,单击“形状填充”,“形状轮廓”或“形状效果”,然后选择所需的格式选项。
Check on this article in John Peltier's site,2007年,2003年之间的代码比较非常有用。那你为什么不将工作簿保存到EXCEL 2010 ?
Sub FormatConnector2003(oConnector As Shape)
With oConnector
If .Connector Or .Type = msoLine Then
' rough approximation of the Excel 2007 preset line style #17
.Line.EndArrowheadStyle = msoArrowheadTriangle
.Line.Weight = 2
.Line.ForeColor.RGB = RGB(192, 80, 77)
.Shadow.Type = msoShadow6
.Shadow.IncrementOffsetX -4.5
.Shadow.IncrementOffsetY -4.5
.Shadow.ForeColor.RGB = RGB(192, 192, 192)
.Shadow.Transparency = 0.5
.Visible = msoTrue
End If
End With
End Sub
Sub FormatConnector2007(oConnector As Shape)
With oConnector
If .Connector Or .Type = msoLine Then
.Line.EndArrowheadStyle = msoArrowheadTriangle
.ShapeStyle = msoLineStylePreset17
End If
End With
End Sub