excel - 将用户名(数组)与电子邮件(数组)匹配
问题描述
使用 Excel 2013。经过多年的寻找和适应,我的第一篇文章。
我正在尝试将当前 App 用户(即“John Smith”)与他的电子邮件地址“jsmith@work.com”进行匹配。
使用两个字符串:1 个用于用户(1 到 3),另一个用于 eaddress(1 到 3)。我想获取当前用户的电子邮件地址,以便在单独的 Sub 中使用,以便在电子邮件中抄送当前用户。
我尝试了一个For Each i In user
,并将 eName 设置为eaddress(i)
. 这仅返回最后列出的用户/电子邮件。
Private Sub (useremail)
Dim user (1 To 3), eaddress (1 To 3), fullName, eName As String
fullName = Application.UserName
user(1) = "John Smith"
user(2) = "Debbie Adams"
user(3) = "Karen Jones"
eaddress(1) = "jsmith@work.com"
eaddress(2) = "dadams@work.com"
eaddress(3) = "kjones@work.com"
For i = 1 To 3
'For Each i In user
fullName = user(i)
eName = eaddress(i)
'Exit For
debug.print "User is " & fullname & "email to " & eName
Next i
寻找当前用户的 eaddress/eName(用于单独的 Sub to email 文件)。
解决方案
您可以使用 aDictionary
使这更容易
Private Sub UsereMail()
Dim dictInfo, fullName
fullName = Application.UserName
Set dictInfo = CreateObject("Scripting.Dictionary")
dictInfo.Add "John Smith", "jsmith@work.com"
dictInfo.Add "Debbie Adams", "dadams@work.com"
dictInfo.Add "Karen Jones", "kjones@work.com"
If dictInfo.Exists(fullName) Then
Debug.Print "User is " & fullName & " email to " & dictInfo(fullName)
End If
End Sub
推荐阅读
- json - React js嵌套循环数组
- windows - 您的 Windows 许可证即将到期
- python - Pyinstaller 在编译时排除 SubModules
- python - Dhitools plot_item 导致 python 失败
- android - 我的 multidex 没有解析(它仍然是红色的)
- wordpress - WP 内容未在编辑器中加载
- flutter - 为什么它在颤动中显示'方法'rootAncestorStateOfType'在null上被调用'?
- visual-studio-code - VSCode 扩展修改 files.exclude 配置
- c# - 隐式转换和显式转换是否具有相同的性能?
- r - 行规范化和列规范化的区别