我有这个脚本,我正在使用库存列表。 对于每种产品都有一个计数和一个再订购限制。如果计数小于再订购限制,我会发送一封电子邮件询问订购更多。VBA - 下标超出范围
我试着运行脚本,它给了我一个编译错误。 Subscript out of range - Run-time error9
这是我的代码。
Sub sendEmail()
'
' sendEmail Macro
'
'
Dim olApp As Object, olMail As Object
Dim MyData
Dim i As Long
Set olApp = GetObject(, "Outlook.Application")
' ~~> I have taken 70 rows
MyData = ThisWorkbook.Sheets("HDD").Range("D2:E70")
For i = LBound(MyData) To UBound(MyData) - 1
If MyData(i, 5) > MyData(i, 4) Then
Set olMail = olApp.CreateItem(0)
Debug.Print MyData(i, 2)
With olMail
.To = "[email protected]"
.Subject = "Sent from Excel"
.Body = MyData(i, 2)
.Send
End With
End If
Next i
End Sub
我的工作是这样的:
No - Product - Description - Count - Reorder
---------------------------------------------
1 Pen - 4 5
当你调试我的价值是什么?第一遍是零还是'空'? –
+1只是因为我喜欢那些'~~>'花哨的评论箭头:) –
@PortlandRunner i = 1; – user2771150