【问题标题】:Make cells look like buttons使单元格看起来像按钮
【发布时间】:2015-11-12 22:08:19
【问题描述】:

我正在尝试使 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

它适用于一个单元格:

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

我想要的是一些东西,而不使用实际的命令按钮,例如:

【问题讨论】:

  • 它永远不会按您计划的方式工作。看看你的 ONE CELL 例子。单元格之间只有一个边界,但您的想法假设相邻单元格之间有两个边界。由于只有一个共享边框,代码必须决定将什么应用于公共边框,并且默认使用 TOP 和 LEFT 边框设置。
  • 如果您愿意在明显相邻的单元格之间隐藏一列(垂直方向也隐藏一列),则可以进行类似的操作。
  • 您将所有边缘设置为白色。检查您的代码:当您将单元格的top edge 设置为白色时,同时设置其上方单元格的bottom edge。左边缘和右边缘也是如此。边缘在相邻单元之间是共同的
  • 我就是这么想的。我正在做一个扫雷。因为,我只知道 VBA 一个月,所以在两者之间添加额外的行对我来说工作量太大了。大声笑感谢 Excel 英雄!
  • 我同意 ASH,但如果我不给它剃须和光,似乎没有其他方法可以给它带来 3D 般的感觉。我不知道如何让相邻的边框有两种颜色......哈哈,作为 VBA 的新手,这是我能想到的最好的:)谢谢 ASH

标签: vba excel


【解决方案1】:
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

【讨论】:

  • 这是一个很好的效果,我会赞成它,但不幸的是它并不是 OP 正在寻找的。​​span>
  • 非常感谢您抽出宝贵时间编写此代码。这不是我想要的,但结果看起来非常漂亮。谢谢:)
猜你喜欢
  • 2019-06-01
  • 2011-07-28
  • 1970-01-01
  • 2012-11-26
  • 2012-07-06
  • 1970-01-01
  • 2016-04-30
  • 2011-07-10
相关资源
最近更新 更多