Here's more detail of what I have done. My aim is to download attachments from a shared mailbox whenever new emails arrive. I set up a rule to detect the arrival of new emails and wrote a script to download attachments. I tried the download function in my own mailbox first and the code is this:
Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)MsgBox ("Started")
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
Dim strFile As String
Dim sFileType As String
sSaveFolder = "(name of my folder)"
For Each oAttachment In MItem.Attachments
strFile = oAttachment.FileName
sFileType = LCase$(Right$(strFile, 5))
'MsgBox (sFileType)
If sFileType = ".xlsm" Then
oAttachment.SaveAsFile sSaveFolder & "" & oAttachment.DisplayName
End If
Next
End Sub
The code above worked. I tried methods like CreateRecipient and GetSharedDefaultFolder to access the shared mailbox but all failed. This is not the problem. The problem is that after this, when I tried to run the above code again, this situation I mentioned in #1 happened.
Some information that may be useful:
- my company disabled Macro
- no matter I put the above code in Module or in ThisOutlookSession, the situation in #1 happened.