我正在编写宏来查找并回复来自共享邮箱的电子邮件。问题是解决共享邮箱。我试过了adjusting this code。
Const olFolderInbox = 6
Sub Reply()
Dim olMail As Outlook.MailItem
Dim myNamespace As Outlook.Namespace
Dim myRecipient As Outlook.Recipient
Set myNamespace = Application.GetNamespace("MAPI")
Set myRecipient = myNamespace.CreateRecipient("shared@mailbox.com")
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objInbox = objNamespace.GetSharedDefaultFolder(myRecipient, olFolderInbox)
strFolderName = objInbox.Parent
Set objMailbox = objNamespace.Folders(strFolderName)
Set objFolder = objMailbox.Folders("Inbox")
Set colItems = objFolder.Items
Dim i As Long
Dim Folder As Outlook.Folder
i = 1
For Each olMail In objFolder.Items
If InStr(olMail.Subject, "test") <> 0 Then
Set oReply = olMail.Reply
oReply.HTMLBody = "Thank you!!!" & oReply.HTMLBody
oReply.Display
i = i + 1
End If
Next
End Sub
但是我收到了这个错误:
你可以告诉我我做错了什么吗?对象在此行不支持此属性或方法。
设置myNamespace = Application.GetNamespace(“MAPI”)