更新:我是个白痴
所以这给了我经典的Object required错误,我不是百分之百确定原因。它适用于第一个循环然后第二个错误... meh?
Private Sub Email_Click()
Dim counter As Integer
Dim address As String
Dim startCell
Dim currentCell
counter = 0
startCell = "B5"
Set currentCell = ThisWorkbook.Worksheets("Follow Up").Range(startCell) '.Offset(counter, 0).Value
While currentCell > 0
address = currentCell.Offset(counter, 2).Value
If (currentCell.Offset(counter, 2) > 0) Then
CreateMail (address)
<s>counter = counter + 1</s>
currentCell = ThisWorkbook.Worksheets("Follow Up").Range(startCell).Offset(counter, 0)
Else
End If
**counter = counter + 1**
Wend
counter = 0
End Sub
这就是现在这张纸的样子。这都是考验。
Date Member ID Name Email Notes
1948828 bobby bob@bob.com awsda
2166295 jim
2274434 james Me@you.com
编辑*添加CreateMail代码
Private Sub CreateMail(address As String)
Dim myolapp As Object
Dim myitem As Object
Set myolapp = CreateObject("Outlook.Application")
myolapp.Session.Logon
Set myitem = myolapp.CreateItemFromTemplate(ThisWorkbook.Worksheets("Data").Range("B11").Value + "NMFU.oft")
myitem.Body = "Hey test" & myitem.Body
myitem.Display 'or send
myitem.to = address
End Sub