简体   繁体   English

运行时错误'1004'Range.boarders

[英]Run-time error '1004' Range.boarders

Receiving an error with this segment of code. 使用此段代码接收错误。 I am using code from Excel 2010 worksheet, where it works without issue, on an Excel 2013 computer. 我在Excel 2013计算机上使用Excel 2010工作表中的代码,它可以正常工作。 All of my libraries have updated correctly and we are not sure why this does not seem to be forward compatible. 我的所有库都已正确更新,我们不确定为什么这似乎不是向前兼容的。

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

Also receiving an error here: 此处也收到错误:

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

Now, both .LineStyle and .Weight work in other areas of the code so we are not sure what to do about this. 现在, .LineStyle.Weight都在代码的其他区域工作,所以我们不确定如何处理这个问题。

When I record a macro I get this: 当我录制宏时,我得到了这个:

With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With

When I add the range in it works to perfection (again this is on a clean sheet): 当我添加范围时,它的工作就完美了(再次,这是在一张干净的纸上):

With Range("C2:I20")
    .Borders(xlEdgeBottom).Weight = xlMedium
    .Borders(xlEdgeRight).Weight = xlMedium
    .Borders(xlEdgeLeft).Weight = xlMedium
    .Borders(xlEdgeTop).Weight = xlThick
End With

Any assistance would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

I don't know if this will help but instead of using with Me.Range try setting a sheet object and working from there. 我不知道这是否会有所帮助,而不是使用Me.Range尝试设置一个工作表对象并从那里工作。 I tend to get less glitching this way. 我倾向于以这种方式减少故障。 example

    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

The only other thing I can think of is merged cell issues, where half the cell is in the set range, and half the cell is not. 我能想到的另一件事是合并的单元问题,其中一半的单元格在设定的范围内,而一半的单元格不在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM