2

在 Sub DateDiff 中实现 Sub TabPaint 时出现错误

Public Sub TabPaint(ss As Integer, cc As Integer)
  With Sheets(ss).Tab
      .Color = cc
      .TintAndShade = 0
  End With
End Sub


Public Sub DateDiff(date1 As String, date2 As String, shn As Integer)
    If DateDiff("d", date1, date2, vbMonday, vbFirstJan1) < 0 Then
        TabPaint (shn, 255)
    Else
        TabPaint(shn,5287936)
    End If
End Sub
4

2 回答 2

6

在 VBA 中,如果您没有将函数的返回值分配给任何内容,或者该方法是子例程,则省略括号,因此请尝试以下操作:

Public Sub TabPaint(ss As Integer, cc As Integer)
  With Sheets(ss).Tab
      .Color = cc
      .TintAndShade = 0
  End With
End Sub


Public Sub DateDiff(date1 As String, date2 As String, shn As Integer)
    If DateDiff("d", date1, date2, vbMonday, vbFirstJan1) < 0 Then
        TabPaint shn, 255
    Else
        TabPaint shn, 5287936
    End If
End Sub
于 2013-08-08T11:53:47.403 回答
0

当你像你的 sub TabPaint 这样调用 subs 时,你不能使用括号,所以试试这个:

TabPaint shn, 255

而不是这个:

TabPaint(shn, 255)
于 2013-08-08T11:58:12.003 回答