[英]Run-time error '1004' Range.boarders
使用此段代码接收错误。 我在Excel 2013计算机上使用Excel 2010工作表中的代码,它可以正常工作。 我的所有库都已正确更新,我们不确定为什么这似乎不是向前兼容的。
With Me.Range("T3:Y196")
.borders(xlEdgeBottom).Weight = xlThick
.borders(xlEdgeLeft).Weight = xlThick
.borders(xlEdgeRight).Weight = xlThick '<--- error here
.borders(xlEdgeTop).Weight = xlThick '<--- once above code is commented out error occurs here
End With
此处也收到错误:
With Range(ConvertColumnNumberToLetter(questionTextCol - 1) & CStr(myRow) & ":" & ConvertColumnNumberToLetter(instructionsCol) & CStr(myRow)).borders(xlEdgeTop)
'above Range gives same result as "T3:Y196" but I hard coded it to do some testing in the previous With Statement
.LineStyle = xlContinuous '<--- Error
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium '<--- Error
End With
现在, .LineStyle
和.Weight
都在代码的其他区域工作,所以我们不确定如何处理这个问题。
当我录制宏时,我得到了这个:
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
当我添加范围时,它的工作就完美了(再次,这是在一张干净的纸上):
With Range("C2:I20")
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlThick
End With
任何帮助将不胜感激。 谢谢!
我不知道这是否会有所帮助,而不是使用Me.Range尝试设置一个工作表对象并从那里工作。 我倾向于以这种方式减少故障。 例
Dim TheSheet as Worksheet
Set TheSheet = Sheets("Your Sheet Name")
With TheSheet.Range("T3:Y196")
.borders(xlEdgeBottom).Weight = xlThick
.borders(xlEdgeLeft).Weight = xlThick
.borders(xlEdgeRight).Weight = xlThick '<--- error here
.borders(xlEdgeTop).Weight = xlThick
End With
我能想到的另一件事是合并的单元问题,其中一半的单元格在设定的范围内,而一半的单元格不在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.