【发布时间】:2014-01-01 02:57:07
【问题描述】:
收到与此代码段有关的错误。我正在使用 Excel 2010 工作表中的代码,它可以在 Excel 2013 计算机上正常工作。我所有的库都已正确更新,我们不确定为什么这似乎不向前兼容。
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
任何帮助将不胜感激。谢谢!
【问题讨论】:
-
.borders(xlEdgeRight).Weight = xlThick在xl2013为我工作 -
我认为会发生这种情况,但无法弄清楚这里出了什么问题
-
您是否直接从 VBA 复制代码?如果是,那么我很好奇为什么
.borders中的b是小写字母。您是否使用任何具有该名称的变量? -
是的,我确实直接从 VBA 复制,我注意到它也是小写的。甚至没有接近该名称的变量。
-
哦,在模块的另一个子中发现了一个变量,而不是一个名为边框的工作表。我会处理这个问题,看看是否能解决问题。谢谢!