k4j8 / outlook-move-to-thread

Microsoft Outlook VBA to move emails to the same folder as the rest of the email thread
MIT License
32 stars 7 forks source link

Not working in Outlook 2016 #1

Closed CGDaveMac closed 5 years ago

CGDaveMac commented 5 years ago

I have been trying to get this working in Outlook 2010 and I imported the two files individually and the macro runs fine, no errors, just a pop up that no folders were found. I have been longing for this capability for a long time! Any ideas?

k4j8 commented 5 years ago

Same here! Glad you find this functionality useful.

The "No folders found" error occurs when none of the emails in the conversation are in a folder other than Inbox or Sent Items. To see the other emails in the conversation, enable conversation view by clicking the View tab in the Outlook Ribbon and then checking the box for "Show as Conversations."

Then, move the first email in the conversation to a specific folder. Next, run the macro on the latest email in the conversation. A notification should appear saying it moved the second email to the same folder as the first.

CGDaveMac commented 5 years ago

Thanks for the quick response! I will have to try again tomorrow at work, but I do have conversation view on. Is there a limit to how "deep" the folders are? Most of mine are nested 3-4 (or more) layers deep.

k4j8 commented 5 years ago

There should be no limit to how deep your folders are since it treats the folder path as a single string rather than nested folders.

I did notice that it didn't work if the email chain contained a meeting. The commit I just pushed (204ec6c820d99513221a5b8a7ef274cf801dead0) fixes the issue for me. If this doesn't fix it or the issue is something else, can you try a minimal example such as the following?

  1. Send an email to yourself.
  2. Reply to the email you just sent yourself.
  3. Move the first message to a folder other than Inbox or Sent Items.
  4. Run the macro on the second message.

The macro should move the second message to the same folder as the first message and provide a message box stating it moved.

CGDaveMac commented 5 years ago

I will try tomorrow.

On the emails I tried, I don't think any had meetings. Also, I don't think this should affect anything, but my security settings required that macros be signed, so I signed the macro with my own credentials.

CGDaveMac commented 5 years ago

Found the problem, but I can't exactly work out why. (I did not have enough time to really debug today.)

In GetConversationInforation, there is a problem with the following code:

If (InStr(fld.FolderPath, "Inbox") = 0) And (InStr(fld.FolderPath, "Sent Items") = 0) And (IsInListBox = False) Then Me.ListBox1.AddItem fld.FolderPath End If

As written, this code is executed the first time, and never matches the three conditions and skips down to "No Folders Found." I removed the If statement and everything works. I imagine the unintentional consequence is that it will try to move emails to the Inbox if that's the only place they are.

CGDaveMac commented 5 years ago

I had some additional time, and found the problem... my FolderPath ALWAYS contains “Inbox” because all of my folders are sub folders of the inbox. I solved this by moving them into an Archive folder. I wonder if this is the best practice and should be added to the README, or the code for searching could be tweaked to ensure the string doesn’t end with the word Inbox.

k4j8 commented 5 years ago

Good catch! I have a fix I will push today. The issue is that in order to avoid populating the ListBox with Inbox, Sent Items, and Calendar on every thread, the macro ignored all folders with those names anywhere in the path.

The fix I have will ignore those folders but not any of their subfolders.

polytan02 commented 5 years ago

Thanks buddies, I'm looking forward the update to test it! Not sure how to update a self created macro though...

k4j8 commented 5 years ago

Please verify commit 81a42e4affaad100876fef6093952f1ff195a7af fixes the issue. To update the macro, download the changed files (ListThreadFolders.frm and ListThreadFolders.frx) and import them.

If it does not fix the issue, could you copy and paste the details from the Immediate Window? It can be accessed within the VBA editor under the View menu or with the shortcut Ctrl+G. Thanks for the feedback!

polytan02 commented 5 years ago

Hello @KyleWJohnston

I updated the macro and when I run it I have a new error :

Run time error 438
Object doesn't support this property or method

When I click on the "debug" button it highligths : ==> ListThreadFolders.Show

k4j8 commented 5 years ago

I appreciate the feedback. Can you check what VBA references are enabled? Here's how:

  1. Open VBA editor with Alt+F11.
  2. Under the Tools menu, click References.
  3. Make sure at least the following are checked:
    • Visual Basic For Applications
    • Microsoft Outlook 16.0 Object Library
    • Microsoft Forms 2.0 Object Library

Also, are there any messages in the Immediate Window after running the macro? Open the Immediate Window with Ctrl+G from the VBA editor and copy any messages here.

polytan02 commented 5 years ago

The following seem activated on my end :

Visual Basic For Applications
Microsoft Outlook 16.0 Object Library
Microsoft Office 16.0 Object Library
OLE Automation
Microsoft Forms 2.0 Object Library
polytan02 commented 5 years ago

Oh and nothing in the immediate window, Only the error code I list above (code 438 and the line ListThreadFolders.Show is highlighted in yellow when I click on debug.

CGDaveMac commented 5 years ago

Just realized I actually am using Outlook 2016, not 2010.

I got the same error, but stepped into the debugger. Some of the Debug lines produce errors, but not all. Here are the ones that do, plus a screenshot of the error:

Debug.Print ("Selected item: " & selectedItem)

'Debug.Print ("Moved '" & objItem & "' to '" & objDestFolder & "'")

'Debug.Print ("Skipped moving '" & objItem & "' to '" & objDestFolder & "' (same folder)")

I commented the out and the macro works perfectly, including items that are in Inbox sub folders.

Capture

polytan02 commented 5 years ago

I commented the 3 debug lines and it works. It feels so good. Do you think we could put a timer for the popup to disappear by itself after 2 second for example ? Or better, when we click on the macro a drop down list appear showing the detected folders and we simply select where to send ? No popup window then, even better.

k4j8 commented 5 years ago

Great find! I'm not sure what the deal with those debug lines is. I'm running Outlook 2016 as well and they all work fine on my machine. I'll comment out those lines to close this issue, but I'd like to know why they're not working.

To remove the confirmation window after an email is automatically moved (only 1 folder in the thread), comment out the following line near the bottom of GetConversationInformation: MsgBox ("Moved email(s) to " & Me.ListBox1.Column(0, 0))

We can look for alternatives to the MsgBox and ListBox, but it should be a separate issue. Pressing enter will accept the MsgBox "Moved email(s) to..." confirmation.

k4j8 commented 5 years ago

I might have found the issue, but I don't know why it works on my computer. Do the following debug lines work? I specified properties that return strings.

Debug.Print ("Selected item: " & selectedItem.ConversationTopic)
Debug.Print ("Moved '" & objItem.ConversationTopic & "' to '" & objDestFolder.name & "'")
Debug.Print ("Skipped moving '" & objItem.ConversationTopic & "' to '" & objDestFolder.name & "' (same folder)")
CGDaveMac commented 5 years ago

Those work just fine.

polytan02 commented 5 years ago

So should this bug be closed and the rest lived into feature request?

k4j8 commented 5 years ago

I'll close this with a commit tonight. The rest can be a feature request.

k4j8 commented 5 years ago

Forgot to push to GitHub. Closed with commit 1f3e1c205514a90ce495b4411c236a1bacdc2acf.