[英]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.