我写了这个脚本来请求来自不同团队的名单,但代码不起作用..需要帮助来检查我错在哪里。
Sub RosterRequest()
Dim counter As Integer
Dim outapp As Object
Dim outmail As Object
Set outapp = CreateObject("Outlook.Application")
Set outmail = outapp.CreateItem(0)
Do While counter < 5
counter = counter + 1
c = Cells(counter, 1).Value
d = Cells(counter, 2).Value
MsgBox ("loop number " & counter & " Name is " & c & " Email is " & d)
With outmail
.to = d
.Subject = "Roster Request"
.Body = "Hi " & c & " Please Share the roster for your team "
.send
End With
Loop
End Sub
答案 0 :(得分:0)
在VBA编辑器中&gt;转到工具&gt;参考文献&gt;并选择Microsoft Outlook 12.0对象库
一个。 c = ThisWorkbook.Sheets(&#34; Shee1&#34;)。Cells(counter,1).Value
湾d = ThisWorkbook.Sheets(&#34; Shee1&#34;)。Cells(counter,2).Value
counter = 0
Do while counter&lt; 5
... ..
一个。您已登录。
湾要通过代码发送邮件,Outlook需要防病毒软件,请检查是否有防病毒软件。
我。要检查转到文件&gt;选项&gt;信托中心&gt;信任中心设置&gt;编程访问并查找防病毒状态
答案 1 :(得分:0)
将createItem(0)指令放在do while循环中,如下所示
Do While counter < 5
Set outmail = outapp.CreateItem(0)
counter = counter + 1
c = Cells(counter, 1).Value
d = Cells(counter, 2).Value
MsgBox ("loop number " & counter & " Name is " & c & " Email is " & d)
With outmail
.to = d
.Subject = "Roster Request"
.Body = "Hi " & c & " Please Share the roster for your team "
.send
End With
Loop