让细胞看起来像纽扣

时间:2015-11-11 22:02:36

标签: excel vba excel-vba

我试图让Excel单元看起来像按钮,而不是实际插入按钮。

For Each myCell In Range(BoardSize)
    With myCell
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlThick
        .Borders.Color = RGB(110, 110, 110)
        .Interior.Color = RGB(180, 180, 180)
    End With

        myCell.Borders(xlEdgeTop).Color = RGB(255, 255, 255)
        myCell.Borders(xlEdgeLeft).Color = RGB(255, 255, 255)
Next myCell

适用于一个单元格:

enter image description here

但是在很大范围内它看起来像这样:

enter image description here

我想要的是,不使用实际的命令按钮,如:

enter image description here

1 个答案:

答案 0 :(得分:2)

For Each mycell In Range(BoardSize)
isblack = mycell.Row Mod 2 = 0 Xor mycell.Column Mod 2 = 0
    With mycell
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlThick
        .Borders.Color = RGB(110, 110, 110)
        .Interior.Color = RGB(180, 180, 180)
    End With
If Not isblack Then
        mycell.Borders(xlEdgeTop).Color = RGB(255, 255, 255)
        mycell.Borders(xlEdgeLeft).Color = RGB(255, 255, 255)
End If
Next mycell

另一个带有轻微神器的版本。它跳过奇数行和奇数列

 Dim mycell As Range
For Each mycell In  Range(BoardSize)
evenrow = mycell.Row Mod 2 = 0
evencol = mycell.Column Mod 2 = 0
isblack = evenrow Xor evencol
    With mycell
        .Borders.LineStyle = xlContinuous
        .Borders.Weight = xlThick
        .Borders.Color = RGB(110, 110, 110)
        .Interior.Color = RGB(180, 180, 180)
    End With
If Not isblack Then
        mycell.Borders(xlEdgeTop).Color = RGB(255, 255, 255)
        mycell.Borders(xlEdgeLeft).Color = RGB(255, 255, 255)
End If
If evenrow Or evencol Then mycell.Borders.Color = RGB(180, 180, 180)
If evencol And mycell.ColumnWidth <> 0.1 Then mycell.ColumnWidth = 0.1 Else mycell.ColumnWidth = 5
If evenrow And mycell.RowHeight <> 1 Then mycell.RowHeight = 1 Else mycell.RowHeight = 30
Next mycell