[VBA]怎样将表格加边框、设字体?

假设一范围A4:C100,怎样将此范围设置边框,并将字体改为Arial,字号12号

第1个回答  2011-09-14
录一个宏就可以了。

Sub Macro1()
Dim myRng As Range
Set myRng = [a4:c100]
With myRng.Font
.Name = "Arial"
.Size = 12
End With
myRng.Borders(xlDiagonalDown).LineStyle = xlNone
myRng.Borders(xlDiagonalUp).LineStyle = xlNone
With myRng.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With myRng.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With myRng.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With myRng.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
myRng.Borders(xlInsideVertical).LineStyle = xlNone
myRng.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub追问

如果每句能注釋一下就更好了

参考资料:神龛培训;NICHE TRAINING

第2个回答  2011-09-13
选中A4:C100,右键,设置单元格属性格式,仔细看然后出来的对话框,里面字体、边框都可以设置的。追问

哦,不好意思,不是問的這個,是問用VBA代碼怎麼寫

第3个回答  2011-09-14
Range("A4:C100").Select
With Selection.Font
.Name = "Arial"
.FontStyle = "常规"
.Size = 12
.Underline = xlUnderlineStyleNone
End With本回答被提问者采纳
第4个回答  2021-01-27