测试通过Private Sub Command2_Click() Dim xlapp As New Excel.Application Dim xlbook As Excel.Workbook Dim xlsheet As Excel.Worksheet
xlapp.Caption = "test" Set xlbook = xlapp.Workbooks.Add Set xlsheet = xlbook.Worksheets(1)
xlapp.Range("A1:D4").Select xlapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone xlapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone With xlapp.Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With xlapp.Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With xlapp.Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With xlapp.Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With xlapp.Visible = TrueEnd Sub
Dim xlapp As New Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
xlapp.Caption = "test"
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1)
xlapp.Range("A1:D4").Select
xlapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
xlapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With xlapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With xlapp.Visible = TrueEnd Sub