
Private Sub test5() 'EXCEL单元格格式设置
Dim excelapplication As Object
Dim str As String
str = Application.CurrentProject.Path & "\book1.xls"
Set excelapplication = GetObject(str) '获取指定的EXCEL文件
With excelapplication.sheets(1)
.Range(.Cells(1, 1), .Cells(3, 4)).Borders.LineStyle = xlContinuous '设置单元格的边框
.Range(.Cells(1, 1), .Cells(3, 4)).Borders.ColorIndex = xlAutomatic '设置单元格边框的颜色,可用1~56间的数字设置不同的颜色
.Range(.Cells(1, 1), .Cells(3, 4)).NumberFormat = "0.00%" '设置单元格的值以百分比的形式显示
.Range(.Cells(1, 1), .Cells(3, 4)).interior.ColorIndex = 24 '设置单元格的颜色
.Range(.Cells(1, 1), .Cells(3, 4)).Font.Bold = True '字体加粗
End With
End Sub
单元格边框参数Dim excelapplication As Object
Dim str As String
str = Application.CurrentProject.Path & "\book1.xls"
Set excelapplication = GetObject(str) '获取指定的EXCEL文件
With excelapplication.sheets(1)
.Range(.Cells(1, 1), .Cells(3, 4)).Borders.LineStyle = xlContinuous '设置单元格的边框
.Range(.Cells(1, 1), .Cells(3, 4)).Borders.ColorIndex = xlAutomatic '设置单元格边框的颜色,可用1~56间的数字设置不同的颜色
.Range(.Cells(1, 1), .Cells(3, 4)).NumberFormat = "0.00%" '设置单元格的值以百分比的形式显示
.Range(.Cells(1, 1), .Cells(3, 4)).interior.ColorIndex = 24 '设置单元格的颜色
.Range(.Cells(1, 1), .Cells(3, 4)).Font.Bold = True '字体加粗
End With
End Sub
名称 值 描述
xlContinuous 1 实线。
xlDash -4115 虚线。
xlDashDot 4 点划相间线。
xlDashDotDot 5 划线后跟两个点。
xlDot -4118 点式线。
xlDouble -4119 双线。
xlLineStyleNone -4142 无线条。
xlSlantDashDot 13 倾斜的划线。
单元格字体格式
名称 描述
Bold 加粗
Italic 斜体
Underline 下划线



