要如何在EXCEL 2003或EXCEL 2010版上用VBA實現:當點擊A儲存格時,該儲存格所對應的列、行"外框"會加粗和變色,再點擊B儲存格時,換B的儲存格對應的列、行"外框"加粗&變色,原本A儲存格對應的列行外框恢復原狀,不更改原始格式。?

2015-10-17 2:00 pm
以下程式碼可以變化列、行顏色,但我不知道如何更改列、行的外框粗細及顏色:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Cells.FormatConditions.Delete
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 5
End With
End With
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 5
End With
End Sub
更新1:

這段可以實現列、行外框變色,且可使用複制貼上功能。誰能幫我再修改一下:將外框加粗? Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) Cells.FormatConditions.Delete With Columns(Target.Column).FormatConditions .Delete .Add xlExpression, , "true" .Item(1).Borders(7).ColorIndex = 5 .Item(1).Borders(10).ColorIndex = 5 End With With Rows(Target.Row).FormatConditions .Delete .Add xlExpression, , "true" .Item(1).Borders(8).ColorIndex = 5 .Item(1).Borders(9).ColorIndex = 5 End With End Sub

回答 (1)

2015-10-18 3:23 am
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Cells.Interior.Pattern = xlNone
Cells.Borders.LineStyle = xlNone
With Columns(Target.Column)
.Interior.Color = 65535
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThick
.Borders(xlEdgeBottom).Weight = xlThick
.Borders(xlEdgeLeft).Weight = xlThick
.Borders(xlEdgeRight).Weight = xlThick
End With

With Rows(Target.Row)
.Interior.Color = 65535
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThick
.Borders(xlEdgeBottom).Weight = xlThick
.Borders(xlEdgeLeft).Weight = xlThick
.Borders(xlEdgeRight).Weight = xlThick
End With
End Sub


收錄日期: 2021-05-04 02:01:01
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20151017060000AAqOCiG

檢視 Wayback Machine 備份