【发布时间】:2015-01-06 22:21:46
【问题描述】:
我试图弄清楚如何使用 VBA 检查电子邮件地址是否在公共通讯簿中。我在网上找到了一些代码,对其进行了修改,但代码在“Set doc = view.GetAllDocumentsByKey(ChkEmailAddr)”行给出了错误 91。我认为问题与变量“view”的声明类型或“Set view = b.GetView("People\By Internet Mail") 行中的视图类型有关。”
我很确定我已经激活了所有正确的引用。选择“Lotus Notes Domino 对象”和“Lotus Notes 自动化类”。
我试图获取视图列表,但我不知道该怎么做。您是否在我的代码中看到错误或对我可以尝试进行一些故障排除有什么想法?
Sub CheckEmailAddress()
Dim books As Variant
Dim view As lotus.NotesView
'Dim view As Object
Dim doc As NotesDocumentCollection
Dim dc As NotesDocument
Dim done As Variant
Dim docarr(3, 50) As Variant
Dim ChkEmailAddr As String
ChkEmailAddr = "user@example.com"
Set Session = CreateObject("Notes.Notessession")
books = Session.AddressBooks
done = False
For Each b In books
' check every public address book,
' unless we're already done
If (b.IsPublicAddressBook) Then
Debug.Print TypeName(b)
Call b.Open("", "")
Debug.Print b.Title
' look up person's last name
' in People view of address book
Set view = b.GetView("People\By Internet Mail")
Debug.Print TypeName(view)
'Debug.Print view
'Set view = b.GetView("main")
'Debug.Print TypeName(view)
Set doc = view.GetAllDocumentsByKey(ChkEmailAddr)
' if person is found, display the phone number item
'from the Person document
If Not (doc Is Nothing) Then
For j = 0 To doc.Count
docarr(0, j) = doc.GetNthDocument(j).Items(11).Text
docarr(1, j) = doc.GetNthDocument(j).Items(93).Text
docarr(2, j) = doc.GetNthDocument(j).Items(95).Text
docarr(3, j) = doc.GetNthDocument(j).Items(14).Text
Next j
End If
End If
Next b
findEmailLotus = docarr
结束子
【问题讨论】:
标签: vba lotus-notes