如何以VB控制EXCEL,给单元格(A1:D4)加上外边框,只要外边框,里面的不要。

解决方案 »

  1.   

    测试通过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