Hi all,
I know this is covered in quite a few threads out there, but the code I have just doesn't do what it should do and I have a strong feeling it is how I am declaring the public folder location.
The code below works when I move between pst files, but when I changed it to send form inbox to public... well... nothing happens... i get no errors in the code at all...
Basically I need to move the emails to a folder on the top level of the "all public folders" called "KDDI".
I am quite new to VBA so please be patient any help I can get is very much appreciated! (sorry if I didn't tag out the code, I wasn't sure how... I know that annoys people... sorry!)
Sub MoveToFiled()
On Error Resume Next
Dim ns As Outlook.NameSpace
Dim moveToFolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem
Set ns = Application.GetNamespace("MAPI")
'Define path to the target folder
Set moveToFolder = ns.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.Item("KDDI")
If Application.ActiveExplorer.Selection.Count = 0 Then
MsgBox ("No item selected")
Exit Sub
End If
If moveToFolder Is Nothing Then
MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
End If
For Each objItem In Application.ActiveExplorer.Selection
If moveToFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.Move moveToFolder
End If
End If
Next
Set objItem = Nothing
Set moveToFolder = Nothing
Set ns = Nothing
End Sub
Thanks
Harvi