我正在使用以下vba代碼來應用條件格式。Vba只應用條件格式的頂部/底部邊框?
Sub ResetConditions()
With Worksheets(1).Range("A9:P1048576")
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ROW(B9)=ROW(OFFSET($B$9,COUNTA($B:$B)-2,0))"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Borders
.LineStyle = xlContinuous
.Weight = xlThin
.Color = vbRed
End With
End With
End With
End Sub
的邊框顯示爲這樣:
但我希望它看起來像這樣:
我想只設置頂部/底部像這樣的邊界:
Sub ResetConditions()
With Worksheets(1).Range("A9:P1048576")
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ROW(B9)=ROW(OFFSET($B$9,COUNTA($B:$B)-2,0))"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.Color = vbRed
End With
End With
End With
End Sub
但我不斷收到一個錯誤,無法設置邊框類的linestyle屬性。
請有人能告訴我我要去哪裏嗎?
嘗試錄製宏,而使用頂部設置條件格式邊界格式。你會看到,'Excel'本身將使用'.Borders(xlTop)'而不是'.Borders(xlEdgeTop)'。所以可能[邊框對象](https://msdn.microsoft.com/en-us/library/office/ff837809.aspx)與[FormatCondition.Borders](https:// msdn。 microsoft.com/en-us/library/office/ff196030.aspx)以這種沒有記錄的方式。 –