1

The following is supposed to launch a popup folder picker, and then move the current item to the selected folder.

 Sub MoveItems()
     Dim myNameSpace As Outlook.NameSpace
     Dim myInbox As Outlook.Folder
     Dim mySubFolder As Outlook.Folder
     Dim myDestFolder As Outlook.Folder
     Dim myItem As Object

     Set myNameSpace = Application.GetNamespace("MAPI")
     Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
     Set mySubFolder = myNameSpace.PickFolder
     Set myDestFolder = myInbox.Folders(mySubFolder)
     Set myItem = GetCurrentItem()

     myItem.Move myDestFolder

End Sub

I am getting a Type Mismatch on the line

Set myDestFolder = myInbox.Folders(mySubFolder)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Isendra
  • 57
  • 1
  • 4

1 Answers1

1

That line should be Set myDestFolder = mySubFolder

You may wanna also use If mySubFolder Is Nothing Then Exit Sub just in case user decides to cancel the myNameSpace.PickFolder so you don't get run-time error

Option Explicit
Sub MoveItems()
     Dim myNameSpace As Outlook.NameSpace
     Dim myInbox As Outlook.Folder
     Dim mySubFolder As Outlook.Folder
     Dim myDestFolder As Outlook.Folder
     Dim myItem As Object

     Set myNameSpace = Application.GetNamespace("MAPI")
     Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
     Set mySubFolder = myNameSpace.PickFolder

    If mySubFolder Is Nothing Then Exit Sub

     Set myDestFolder = mySubFolder
     Set myItem = GetCurrentItem()

     myItem.Move myDestFolder

End Sub

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application

    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select

    Set objApp = Nothing
End Function

IsNothing Function

IsNothing returns True if the expression represents an object variable that currently has no object assigned to it; otherwise, it returns False.

0m3r
  • 12,286
  • 15
  • 35
  • 71
  • 1
    Interesting, so with the picker there is no need to select the base folder with myInbox. huh. If I adapted to moving from subfolder to subfolder, would I still need the .parent stuff? I bet not. Thanks!! – Isendra May 03 '17 at 00:09
  • You are moving Items from inbox, you can change that with picker from and to picker and it should work – 0m3r May 03 '17 at 00:34