繁体   English   中英

不支持格式条件边框

[英]FormatConditions Borders not supported

我有一些代码应该格式化带有边框的单元格(FormatConditions),但我得到一个错误,即 object 不受支持

“VBA Object 不支持此属性或方法错误(错误 438)”

有人可以帮忙吗? 我认为这取决于MeinBereich.FormatConditions.Borders(xlEdgeLeft)

Private Sub Workbook_Open()     
    Dim my_month As String
    my_month = Format(Date, "mmmm") + " " + Format(Date, "yy")
    Sheets(my_month).Activate
    Range("A1").Select
     
    LR = Cells(Rows.Count, 1).End(xlUp).Row
    
    Dim DatumColumn As Range
    Dim foundRng As Range
    
    my_day = Format(Date, "dd") + "."
    Set foundRng = Range("B2:AF2").Find(my_day)
    
    Dim MeinBereich As Range
    Set MeinBereich = Range(Cells(foundRng.Row, foundRng.Column), Cells(LR, foundRng.Column))
    MeinBereich.FormatConditions.Delete
    
    
    Dim intErgebnis As Integer 
    intErgebnis = StrComp(foundRng, my_day, vbTextCompare)
    
    If intErgebnis = 1 Then
        With MeinBereich
            .FormatConditions.Add Type:=xlExpression, Formula1:="=100"
            With MeinBereich.FormatConditions.Borders(xlEdgeLeft)
                .LineStyle = xlContinuous
                .Color = -16776961
                .TintAndShade = 0
                .Weight = xlThick
            End With
            With MeinBereich.FormatConditions.Borders(xlEdgeTop)
                .LineStyle = xlContinuous
                .Color = -16776961
                .TintAndShade = 0
                .Weight = xlThick
            End With
            With MeinBereich.FormatConditions.Borders(xlEdgeBottom)
                .LineStyle = xlContinuous
                .Color = -16776961
                .TintAndShade = 0
                .Weight = xlThick
            End With
            With MeinBereich.FormatConditions.Borders(xlEdgeRight)
                .LineStyle = xlContinuous
                .Color = -16776961
                .TintAndShade = 0
                .Weight = xlThick
            End With
        End With
    End If
End Sub

格式条件和边框有点棘手 - 在 VBA 和 GUI 中也是如此:

基本概念:

Dim fc As FormatCondition
With MeinBereich
    .FormatConditions.Delete
    Set fc = .FormatConditions.Add(Type:=xlExpression, Formula1:="=100")
    With fc.Borders(xlBottom)
        .Color = -16776961
    End With
End With

将添加的格式条件分配给变量。 然后你用它来设置格式。

您只有边框xlBottomxlTopxlLeftxlRight

您不能设置/不需要设置线型或粗细。 它总是圆润而轻盈。

如前所述:这在 GUI 中是一样的。 如果你想要通过格式条件的粗线,你必须 go “反向”方式。 使用正常的粗体边框格式化整个范围 - 并根据相反的条件(例如 <> 100)将其设置为“无边框”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM