在邮件范围macros中失败find“真实”

Ron de Bruin那里得到了一个我一直在使用的macros,但是现在我无法在参考文献中find“TRUE”。 “TRUE”是由checkbox生成的,如果我写“yes”,它就会起作用我已经使用了他的页面的原始代码,如下所示:

Sub Test1() 'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm 'Working in Office 2000-2016 Dim OutApp As Object Dim OutMail As Object Dim cell As Range Application.ScreenUpdating = False Set OutApp = CreateObject("Outlook.Application") On Error GoTo cleanup For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants) If cell.Value Like "?*@?*.?*" And _ 'right value is being shown LCase(Cells(cell.Row, "D").Value) = "TRUE" Then 'suddenly skips this phase. 'Shows the right row but nothing happens anymore Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = cell.Value .Subject = "Reminder" .Body = "Dear " & Cells(cell.Row, "A").Value _ & vbNewLine & vbNewLine & _ "Please contact us to discuss bringing " & _ "your account up to date" 'You can add files also like this '.Attachments.Add ("C:\test.txt") .Display 'Or use Display End With On Error GoTo 0 Set OutMail = Nothing End If Next cell cleanup: Set OutApp = Nothing Application.ScreenUpdating = True End Sub 

如果我删除And _ LCase(Cells(cell.Row, "D").Value) = "TRUE"它就像一个魅力。 我希望有人能帮我解决这个问题。

因为你正在查询的值的单元格被链接到(ActiveX)checkbox,所以它的值是一个Booleantypes

所以你必须这样检查它,那就是:

 If Cells(cell.Row, "D").Value Then 'means IF Cells(cell.Row, "D").Value = True 

以下行不正确

 LCase(Cells(cell.Row, "D").Value) = "TRUE" Then 

您正在使用LCase函数将值转换为小写(例如true )…您应该将其更改为

 UCase(Cells(cell.Row, "D").Value) = "TRUE" Then