循环包含电子邮件的两个数组 [英] Loop through two arrays containing emails
本文介绍了循环包含电子邮件的两个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个包含电子邮件地址的数组,然后是另一个名为 emailgroup 的数组,其中包含这两个数组的名称.
I have two arrays containing email addresses and then another array called emailgroup that contains the name of these two arrays.
我想创建一个循环,围绕 emailgroup 数组依次调用其他 2 个数组.
I want to create a loop that loops around the emailgroup array to call the other 2 arrays in turn.
例如,我想在第一个循环中,电子邮件"数组将被调用,但错误消息显示类型不匹配.
I thought for example on the first loop, the "emails" array would be called but the error message says type mismatch.
谁能帮忙修改下面的代码?
Can anyone help modify the code below?
Sub Email_Click()
Dim myOutlook As Outlook.Application
Dim objMailMessage As Outlook.MailItem
Dim emails As Variant
Dim moreemails As Variant
Dim emailgroup As Variant
Set myOutlook = Outlook.Application
Set objMailMessage = myOutlook.CreateItem(0)
emails = Array("a@a.com", "b@b.com")
moreemails = Array("c@c.com", "d@d.com")
emailgroup = Array("emails", "moreemails")
For Each i In emailgroup
currentemail = i
With objMailMessage
.Display
.To = Join(currentemail, ";")
.Subject = ""
.HTMLBody = ""
.Save
.Close olPromptForSave
End With
Next
End Sub
推荐答案
emailgroup = Array("emails", "moreemails")
与数组数组不同:
emailgroup = Array(emails, moreemails)
然后,应该使用 LBound
和 UBound
迭代一个数组:
Then, an array should be iterated over with LBound
and UBound
:
Dim i as Long
For i = LBound(emailgroup) to UBound(emailgroup)
...
.To = Join(emailgroup(i), ";")
Next
这篇关于循环包含电子邮件的两个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文