特定边框的 VBA 条件格式

发布于 2025-01-16 20:47:58 字数 813 浏览 1 评论 0原文

嘿嘿, 因此,我尝试使用 VBA 添加条件格式以补偿其他一些编码,这些编码会不时更改范围。我的问题是,我只将条件格式应用于 xlEdgeRight 和 xlEdgeLeft。但是,VBA总是告诉我它无法设置边框样式。有什么想法吗?

Dim rngMark As Range
Dim DateCond As FormatCondition
Dim BordNum As Long

Call wsDef
Set rngMark = wksS.Range("E11:CPB25")

rngMark.FormatConditions.Delete
Set DateCond = rngMark.FormatConditions.Add(Type:=xlExpression, Formula1:="=AND(TODAY()>=E$7,TODAY()<F$7)")
DateCond.SetFirstPriority
With DateCond
    .StopIfTrue = False
    .Font.ThemeColor = xlThemeColorAccent2
    .Font.Bold = True
    .Borders.LineStyle = xlNone
    .Borders.LineStyle = xlNone
End With
For BordNum = 7 To 8
    With DateCond.Borders(BordNum)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Color = -16776961
        .Weight = xlThin
    End With
Next BordNum

Hej,
So I am trying to use VBA to add conditonal formatting to compensate for some other coding, which changes the ranges from time to time. My problem is, that I only the conditional formatting to apply to xlEdgeRight and xlEdgeLeft. However, VBA always tells me that it cannot set the border style. Any ideas?

Dim rngMark As Range
Dim DateCond As FormatCondition
Dim BordNum As Long

Call wsDef
Set rngMark = wksS.Range("E11:CPB25")

rngMark.FormatConditions.Delete
Set DateCond = rngMark.FormatConditions.Add(Type:=xlExpression, Formula1:="=AND(TODAY()>=E$7,TODAY()<F$7)")
DateCond.SetFirstPriority
With DateCond
    .StopIfTrue = False
    .Font.ThemeColor = xlThemeColorAccent2
    .Font.Bold = True
    .Borders.LineStyle = xlNone
    .Borders.LineStyle = xlNone
End With
For BordNum = 7 To 8
    With DateCond.Borders(BordNum)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Color = -16776961
        .Weight = xlThin
    End With
Next BordNum

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若沐 2025-01-23 20:47:58

编程格式条件——尤其是边框——有点特殊。

在这种情况下,您必须使用 xlLeft = -4131 和 xlRight = -4152:

Dim BordNum As Long
Dim arrBordNum(1) As Long
arrBordNum(0) = -4131   'xlleft
arrBordNum(1) = -4152   'xlright
For BordNum = 0 To UBound(arrBordNum)
    With DateCond.Borders(arrBordNum(BordNum))
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Color = -16776961
        .Weight = xlThin
    End With
Next BordNum

Programming formatconditions - especially borders - is a bit special.

You have to use xlLeft = -4131 and xlRight = -4152 in this case:

Dim BordNum As Long
Dim arrBordNum(1) As Long
arrBordNum(0) = -4131   'xlleft
arrBordNum(1) = -4152   'xlright
For BordNum = 0 To UBound(arrBordNum)
    With DateCond.Borders(arrBordNum(BordNum))
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Color = -16776961
        .Weight = xlThin
    End With
Next BordNum

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文