I have Outlook code which checks specific subject email in shared mailbox (Inbox) and records the email body data in Excel (yet to add code) and should move the email to MIAL folder.
I get an error while moving emails to MIAL folder.
"Variable not defined"
Folder (MIAL) was created manually. When I code to move emails to default folder like "Drafts" or "Sent Folder" its working.
Option Explicit
Public Sub Example()
Dim olNs As Outlook.NameSpace
Set olNs = Application.GetNamespace("MAPI")
Dim Recip As Outlook.Recipient
Set Recip = olNs.CreateRecipient("[email protected]") 'update email
Dim SharedInbox As Outlook.Folder
Set SharedInbox = olNs.GetSharedDefaultFolder(Recip, _
olFolderInbox) 'Inbox
Dim Movefolder As Outlook.Folder
Set Movefolder = olNs.GetSharedDefaultFolder(Recip, _
olFolderMIAL) 'Folder
Dim Item As Outlook.MailItem
For Each Item In SharedInbox.Items
'If (Item.subject = "TSP") Then
Debug.Print Item.subject
Item.Move Movefolder
'End If
Next
End Sub