我的VBA代码中的错误在哪里



我写了此脚本以向不同的团队请求名册,但是代码不起作用。.需要帮助来检查我错了。

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

将createItem(0(指令放入do中的exterem(0(

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
  1. 检查您是否包括Microsoft Outlook 12.0对象库

在VBA编辑器> Goto工具>参考>中,然后选择Microsoft Outlook 12.0对象库

  1. 而不是使用c =单元格(计数器,1(。值和d =单元格(计数器,2(。值:

a。c = thisworkbook.sheets(" shee1"(。单元格(counter,1(。值

b。d = thisworkbook.sheets(" shee1"(。单元格(counter,2(。值

  1. 也要在循环时尝试counter = 0:

counter = 0

在计数器&lt时做;5

…..

  1. 检查Outlook是否已配置。

a。您已登录。

b。要通过代码发送邮件,Outlook要求使用防病毒软件,请检查您是否有一封。

i。要检查goto文件>选项>信任中心>信任中心设置>编程访问并查找防病毒状态

相关内容

最新更新