电子邮件范围,而不是行
我正在尝试运行Excel工作簿的表格2,以便向客户发送电子邮件范围。
范围将是A1:B30,C1:D30,E1:F30等,其帐号在A1和电子邮件在B1和下面的信息。
每次我尝试运行电子邮件时,都会出现:
运行时错误1004
然后继续出错
对象已被移动或删除
是否有另一种电邮范围或方式来修改此代码的方式?
Sub EmailRanges() Dim cr As Range Set cr = [b1] ActiveWorkbook.EnvelopeVisible = True Do While cr <> "" cr.Offset(, -1).Resize(30, 2).Select With ActiveSheet.MailEnvelope .Introduction = " Good Morning" .Item.To = cr .Item.Subject = "Just testing, sorry for filling you inbox ^_^ " .item.Send ' to send .Item.Display ' to test End With MsgBox cr & " receives " & Selection.Address Set cr = cr.Offset(, 2) Loop Application.ScreenUpdating = True MsgBox "The Customers Have Been Notified" End Sub
你需要更加明确你的引用(工作簿,工作表,…)。
Thx to @Ralph:
只有在纸张被激活后才能select范围。 否则,你会得到一个错误。
这在我的电脑上顺利运行:
Sub Email_Ranges() Dim rG As Range Dim RangeToSend As Range Dim CustomerMail As String Set rG = ActiveWorkbook.ActiveSheet.[b1] ActiveWorkbook.EnvelopeVisible = True Do While rG.Value <> vbNullString CustomerMail = rG.Value Set RangeToSend = rG.Offset(, -1).Resize(30, 2) 'With RangeToSend.Parent.MailEnvelope ''Uncomment below if you get an error rG.Parent.Activate RangeToSend.Select With Selection.Parent.MailEnvelope .Introduction = "Good Morning" With .Item .To = CustomerMail .Subject = "Just testing, sorry for filling your inbox ^_^ " .display 'to test .Send 'to send End With End With Debug.Print CustomerMail & " receives " & RangeToSend.Address Set rG = rG.Offset(, 2) Loop ActiveWorkbook.EnvelopeVisible = False End Sub