我有一个excel列表,我想创建一个按钮,使用模板在列表中发送电子邮件,目标电子邮件地址在列K中,但我只想在列A显示为YES时发送它。
我写了一个脚本来循环我想要的每一行,看看列A是否有"是"或不,如果是,则参考另一个宏。
但我陷入花药宏,我不能指定.to =列K
以下是查找A列是否为YES的循环脚本:
sub agreement2 ()
dim startrow as integer
startrow = 9
dim mylastrow3 as integer
lastrow3 = activesheet.cells(rows.count, 1).end(xlup).row
dim i as integer
for i = 9 to lastrow3
if (cells(i, 1).value = "YES") then
send_letter
end if
end sub
这是我的send_letter脚本
Sub send_letter()
Dim Subject
Dim Body
Dim otlapp As Object
Dim olMail2 As Object
Dim ws As Object
Set otlapp = CreateObject("Outlook.Application")
Set olMail2 = otlapp.CreateItemFromTemplate("\\cpadm001.corp.ocalwa.com\clk\DEPT\CLKDEPT6\IMT\SAO\SSC\Team\Team1\New Joiner Script\agreement.oft")
Set doc2 = olMail2.GetInspector.WordEditor
Set ws = ThisWorkbook.Worksheets("Send Letters")
vTemplateBody2 = olMail2.HTMLBody
Subject2 = "Agreement Letter"
HTMLBody2 = vTemplateBody2
With olMail2
.To = ????????????????.Value
.Subject = Subject2
Set WrdRng = doc2.Range
WrdRng.Paste
.Send
End With
End Sub
任何人都可以帮助K列。非常感谢你。
答案 0 :(得分:0)
send_letter
更改为send_letter(r)
send_letter
到send_letter i
.To = Cells(r, "K").Value