excel 跳过隐藏行- Outlook收件人表

hm2xizp9  于 2023-03-04  发布在  其他
关注(0)|答案(1)|浏览(111)

我已经工作了很多时间在这个代码。工作簿有一个主页控制中心发送多封电子邮件在一个序列了。在我发送第一封电子邮件到收件人表我记录那些谁回应。如果收件人respods然后我过滤他们在发送下一封电子邮件之前。我试图找到一种方法来跳过隐藏行,因为他们包含谁不需要接收第二封电子邮件的联系人。我被难住了。

Sub Send_seq_two()

Dim sh As Worksheet
Dim sh2 As Worksheet
Set sh = ThisWorkbook.Sheets("TheHub")
Set sh2 = ThisWorkbook.Sheets("Tables")
Set sh3 = ThisWorkbook.Sheets("Contacts")
Set OA = CreateObject("Outlook.Application")
Dim msg As Object
Dim sign As String
Dim I As Integer

Dim tbl As ListObject
Set tbl = Application.Range("mt").ListObject

Dim lrow As Integer
lrow = tbl.Range.Rows(tbl.Range.Rows.Count).Row

If sh.Range("B2").Value <> "2" Or sh3.Range("K6").Value = "1" Then
MsgBox "check sequence"
End If

For I = 6 To lrow

Set msg = OA.CreateItem(0)

    If sh3.Range("H" & I).Value <> "" And sh3.Range("K" & I).Value = "" And sh3.Range("J" & I).Value = "1" And sh.Range("B2").Value = "2" Then

    msg.Display
    sign = msg.HTMLBody

    msg.To = sh3.Range("H" & I).Value
    msg.CC = sh3.Range("I" & I).Value
    msg.Subject = sh.Range("B3").Value
    msg.HTMLBody = "<p><span style='font-size:15px;font-family:Calibri,sans-serif;'>Hi " & sh3.Range("D" &     I).Value & ",<br><br>" & sh2.Range("D3").Value & sign
    

    If sh.Range("B4").Value <> "" Then
    msg.attachments.Add sh.Range("B4").Value

    End If

    msg.Send
    
    
    sh.Range("C14").Value = Date
    sh3.Range("K" & I).Value = "1"
    


End If

Next I

End Sub

我尝试使用隐藏行属性失败,但我认为我应用错误。我只想跳过隐藏行,因为它们是我不想发送的电子邮件。我不想完全删除它们。

enxuqcxy

enxuqcxy1#

希望您可以修改下面的代码作为您的要求

dim i as Range, emailRng as Range, r as Long
Set sh3 = ThisWorkbook.Sheets("Contacts")

' to figure out only visible cells after applying filter
set emailRng = sh3.Range("H1:H" & lrow).SpecialCells(xlCellTypeVisible)

for each i in emailRng
    r = i.row
    msg.To = sh3.Range("H" & r).Value
    msg.CC = sh3.Range("I" & r).Value
Next

相关问题