我的Outlook中有两个邮箱。
一个是我的,它会在我登录我的电脑时自动登录我,而另一个我用于邮件反弹。
我真的需要访问邮件帐户的收件箱,但我似乎无法做到。
我无法将邮件帐户的邮箱作为我的默认邮箱
这是我到目前为止的代码:
Public Sub GetMails()
Dim ns As NameSpace
Dim myRecipient As Outlook.Recipient
Dim aFolder As Outlook.Folders
Set ns = GetNamespace("MAPI")
Set myRecipient = ns.CreateRecipient("mail@mail.pt")
myRecipient.Resolve
If myRecipient.Resolved Then
MsgBox ("Resolved")
Set aFolder = ns.GetSharedDefaultFolder(myRecipient, olFolderInbox)
Else
MsgBox ("Failed")
End If
End Sub
我遇到的问题是
Set aFolder = ns.GetSharedDefaultFolder(myRecipient, olFolderInbox)
我收到Resolved msgbox,所以我知道它正在运行但之后我收到错误:
运行时错误
对错误本身并没有太多说明。
有人可以帮帮我吗? 感谢
答案 0 :(得分:3)
如果您要访问的文件夹不是Exchange文件夹,则需要找到它,如果是Exchange文件夹,请尝试登录命名空间。
登录NameSpace
Set oNS = oApp.GetNamespace("MAPI")
oNS.Logon
查找文件夹 据我所知,此代码来自Sue Mosher。
Public Function GetFolder(strFolderPath As String) As Object 'MAPIFolder
' strFolderPath needs to be something like
' "Public Folders\All Public Folders\Company\Sales" or
' "Personal Folders\Inbox\My Folder" ''
Dim apOL As Object 'Outlook.Application '
Dim objNS As Object 'Outlook.NameSpace '
Dim colFolders As Object 'Outlook.Folders '
Dim objFolder As Object 'Outlook.MAPIFolder '
Dim arrFolders() As String
Dim I As Long
On Error GoTo TrapError
strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders() = Split(strFolderPath, "\")
Set apOL = CreateObject("Outlook.Application")
Set objNS = apOL.GetNamespace("MAPI")
On Error Resume Next
Set objFolder = objNS.Folders.Item(arrFolders(0))
If Not objFolder Is Nothing Then
For I = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.Item(arrFolders(I))
If objFolder Is Nothing Then
Exit For
End If
Next
End If
Set GetFolder = objFolder
Set colFolders = Nothing
Set objNS = Nothing
Set apOL = Nothing
End Function