当电子邮件宏以空白值运行时,用户窗体数据输入会冻结...?

时间:2019-06-18 13:14:16

标签: excel vba

因此,我有一个用于将数据输入表中的用户窗体。我还实现了编码,如果您选中列表值旁边的“发送电子邮件”复选框,然后单击“提交”,则会向列表中的人发送电子邮件。在添加此电子邮件编码之前,单击“提交”按钮将立即添加表中的数据行,您可以移至下一行,而无需重新打开表单。现在,尽管此电子邮件代码位于此处,但是如果选中了电子邮件复选框且人员列表为空,并且您单击了提交,则在关闭用户表单之前,数据不会插入表中。有什么办法可以解决这个问题?

用户窗体的图片:
Image of userform with 3 Checkboxes labeled "Send Email" next to combo boxes which have been circled

复选框的电子邮件代码(包括VLookup以获取列表中人员的电子邮件地址) 在用户表单中的其他输入中还留下了几行,以显示它们的设置方式:

If OptionButton4.Value = True Then
ActiveCell.Offset(0, 19).Value = "Reject"
End If

ActiveCell.Offset(0, 20).Value = TextBox11.Value
ActiveCell.Offset(0, 21).Value = TextBox12.Value

Dim i

On Error Resume Next
i = ActiveCell.Row
Sheet2.Cells(i, 13).Value = Application.WorksheetFunction.VLookup(Sheet2.Cells(i, 12).Value, _
Sheet3.Range("AME"), 2, 0)


If emailbox.Value = True Then

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 Sheet2.Range("M" & ActiveCell.Row)
        If cell.Value Like "?*@?*.?*" Then

            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .To = cell.Value
                .Subject = "New C.M.M. Inspection Request! Form #" & Sheet2.Cells(cell.Row, "A")
                .Body = "Dear " & Sheet2.Cells(cell.Row, "L").Value & "," _
                        & vbNewLine & vbNewLine & _
                        "You have been added to a new C.M.M. Inspection _ Request."



                .Send
            End With
            On Error GoTo 0
            Set OutMail = Nothing

            sent.Visible = True
            Else
        End If
    Next cell

cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End If

(其他2个复选框共有3个相同的代码)

在所有其他输入值都设置为输出到活动行中的相应列之后,此代码位于SubmitButton_Click()子的末尾...

0 个答案:

没有答案