【发布时间】:2017-02-27 23:52:40
【问题描述】:
我有这段代码,但我不断在同一行收到属性/方法错误。见下文。我很确定这是我在继续完全运行代码之前需要解决的最后一个问题。非常感谢任何和所有帮助。
“volume CT”是 ChartSheet 的名称
SC2 = ActiveWorkbook.Sheets("Volume CT").SeriesCollection.Count
For i = 1 To SC2 'Run the loop for all the data series [volume]
Debug.Print SC2 'make sure program counts correct amt of series
Dim name As String
name = .FullSeriescollection(i).name
Debug.Print name
End With
'Find series names and change color for solids & area RedZone1
resultx = InStr(1, name, x, vbTextCompare)
'x is the variable name for the "codeWord" to look for
Debug.Print resultx
If resultx <> 0 Then
With ThisWorkbook.Sheets("Volume CT").Chart.SeriesCollection(i).ChartArea.Format.Fill
^^Error 438: Onject 不支持属性或方法
.Visible = msoTrue
.ForeColor.RGB = Red
.Transparency = 0
.Solid
End With
End If
【问题讨论】:
-
Sheets对象是否有Chart对象?在第一行,你正在做Sheets("Volume CT").Series...,但在错误行,你有Sheets("Volume CT").Chart.Series... -
@TylerStandishMan 差不多。
Sheets对象是一个集合,它的Itemgetter(此处隐式使用的默认属性)返回一个Object,因此除此之外没有 IntelliSense。但是在这种情况下,返回对象的运行时类型是Chart...事实上,Chart对象没有Chart成员。 -
@Mat'sMug,谢谢。我没有靠近电脑,也有很长一段时间没有处理 VBA,但这对我来说似乎很奇怪,因为你得到了你已经提到的对象,就像你澄清的那样。
标签: vba methods charts properties formatting