PDA

View Full Version : Moving emails to Public Folders



havrvi
04-11-2014, 06:10 AM
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

westconn1
04-11-2014, 01:46 PM
i get no errors in the code at all...first remove on error resume next, so you will know if any errors occur

havrvi
04-14-2014, 02:16 AM
first remove on error resume next, so you will know if any errors occur

hey,

I did that, no change. I ran through the code using the step into (F8 I think it was) and I get no actual code errors, it just runs through and doesn't do or say anything.
when I purposely do not select an email, it throws up the error as expected. but that's the only thing I can get it to actually do :(

I know my lack of experience doesn't help... but I do also think it's that public folders command... just not sure what.

westconn1
04-15-2014, 03:05 AM
i can not give exact answer as i do not have any public folders, and a different version of outlook, appears to have different objects and constant for public folders