We have recently upgraded from Mailgate to Microsoft Exchange. In Outlook on my PC I had the following code to saved a particular attachment to a specified folder:
The message which contains the attachment I wish to save now appears in an Exchange Public Folder and, when I run the code, the message box appears telling me that the item is of the wrong type.
I think the problem lies in the phrase "Dim myItem As Outlook.MailItem" but I cannot find any information which refers to Exchange. I would be grateful if someone could set me right.
John
Code:
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myOlApp = CreateObject("Outlook.Application")
Set myInspector = myOlApp.ActiveInspector
If Not TypeName(myInspector) = "Nothing" Then
If TypeName(myInspector.CurrentItem) = "MailItem" Then
Set myItem = myInspector.CurrentItem
Set myAttachments = myItem.Attachments
'Prompt the user for confirmation
Rem Dim strPrompt As String
Rem strPrompt = "Are you sure you want to save the first attachment in the current item to the C:\ folder? If a file with the same name already exists in the destination folder, it will be overwritten with this copy of the file."
Rem If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
myAttachments.Item(1).SaveAsFile "N:\DOCS2\Positions\" & _
myAttachments.Item(1).DisplayName
Rem End If
Else
MsgBox "The item is of the wrong type."
End If
I think the problem lies in the phrase "Dim myItem As Outlook.MailItem" but I cannot find any information which refers to Exchange. I would be grateful if someone could set me right.
John