Consulting

Results 1 to 4 of 4

Thread: Moving emails to Public Folders

  1. #1
    VBAX Newbie
    Joined
    Apr 2014
    Posts
    2
    Location

    Moving emails to Public Folders

    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

  2. #2
    i get no errors in the code at all...
    first remove on error resume next, so you will know if any errors occur

  3. #3
    VBAX Newbie
    Joined
    Apr 2014
    Posts
    2
    Location
    Quote Originally Posted by westconn1 View Post
    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.

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •