0

I am trying to move tasks from the To-Do list to an "Inquiries" Task folder.
Preferably it should move the task without having to select it.

This code gives me:

'Runtime Error '424' Object Required'

Original code from https://www.slipstick.com/outlook/macro-move-folder/

Sub MoveTask()
 
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim objItem As TaskItem
    Dim strSignifier As String
     
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderTasks)
    Set objItem = objFolder.Items.Add(olTaskItem) ' this line has the error
    Set objDestFolder = objNamespace.GetDefaultFolder(olFolderTasks).Folders("Inquiries")
 
    strSignifier = "#CT-"
 
    If Left(Item.subject, Len(strSignifier)) = strSignifier Then
        objItem.Move objDestFolder
    End If
               
    Set objDestFolder = Nothing
End Sub
Community
  • 1
  • 1

1 Answers1

0

You need to also Dim and Set objFolder in order to use it, or change it to objDestFolder or objSourceFolder depending on what you are trying to do.

Put Option Explicit at the top of your module and it will help detect these things.

braX
  • 11,506
  • 5
  • 20
  • 33
  • I tried changing the code according to your suggestion, but now I don't even get a prompt to test run the macro, and the tasks also have not moved. Did I need to bind it to a ribbon button or is there something else I am missing? – Ryan Lee May 18 '18 at 16:30
  • @RyanLee [Edit](https://stackoverflow.com/posts/50398490/edit) your question to show your current code. You may find Option Explicit answers the question in your comment. [How do I force VBA/Access to require variables to be defined?](https://stackoverflow.com/questions/1139321/how-do-i-force-vba-access-to-require-variables-to-be-defined). – niton May 19 '18 at 12:55
  • My boss just got back to me and said we'll use the shared task feature in outlook instead. Thank you everyone for your help! – Ryan Lee May 22 '18 at 16:49