找不到真实的"在邮件到范围宏

时间:2016-07-26 09:24:04

标签: excel vba excel-vba

Ron de Bruin 获得了一个我一直在使用的宏,但现在我无法找到" TRUE"在参考栏中。 " TRUE"是从复选框生成的,如果我写了#34;是" 我已经使用了他页面中的原始代码,如下所示:

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",它就像魅力一样。我希望有人可以帮我解决这个问题。

2 个答案:

答案 0 :(得分:1)

以下行不正确

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

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

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

答案 1 :(得分:1)

由于您要查询的值的单元格与(ActiveX)复选框相关联,因此其值为Boolean类型

所以你必须检查它,即:

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