EXCEL2003中,如何用vba把选定的区域用边框修饰,需要代码。(下面是原始状态和更改后的状态)

如果能用VBS,解答追加20分。
2024-12-12 01:02:27
推荐回答(3个)
回答1:

比如对选定区域A1:E6边框修饰,实际上就是四周边框与内部的水平线与垂直线。

一般而言,用宏代码可以如下简化为:

Sub bkxs()

With Range("A1:E6")

    .Borders(xlInsideVertical).LineStyle = xlDot '垂直点线

    .Borders(xlInsideHorizontal).LineStyle = xlDot '水平点线

    .BorderAround ColorIndex:=0, Weight:=xlMedium '四周边框线(稍粗)

End With

End Sub

修饰的本意即是所选择的线型(LineStyle)设置、粗细设置(Weight)。具体可以通过录制宏的办法来选取。

⑴LineStyle的取值可以有以下几种,根据需要选择其一即可。

xlContinuous   

xlDash   

xlDashDot   

xlDashDotDot   

xlDot   

xlDouble   

xlSlantDashDot   

xlLineStyleNone   

⑵Weight的取值可以有以下几种,根据需要选择其一即可。

xlHairline 

xlThin 

xlMedium 

xlThick

特别说明:

代码 .BorderAround ColorIndex:=0, Weight:=xlMedium  包含对所选择线型的颜色和粗细设置。ColorIndex:=0是黑色,ColorIndex:=3红色。

以上代码可以通过选择不同区域、进行不同线型粗细设置测试。此仅供参考!

对选定区域A1:E6外边框为红色效果图如下所示:

 



回答2:

这个最好自己去录制一个宏,理解一下,下次就不用求人了:
譬如选中图中A1:E6
其中 LineStyle、Weight、Clorindex (线条格式、线条粗细、线条颜色)自己可以设置的
With Range(A1:E6).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Range(A1:E6)..Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
这是上、下外边框的设置

With Range(A1:E6).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Range(A1:E6)..Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
这是左、右外边框的设置

With Range(A1:E6).Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Range(A1:E6)..Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
这是内框垂直、水平方向边框的设置

回答3:

03的不知道,我都是用07的直接录制了。格式的代码一般也没必要去记