0

I've used Thunderbird and now moving across to Outlook 2010, PC is Windows 7 Professional, 64 bit machine but I use 32 bit Office 2010.

I have 8 email addresses including 4 gmail addresses: all are IMAP. No exchange servers.

I believe that with IMAP, moving emails from the account inbox means they are no longer on the server so other devices can't see them anymore - happy to be corrected on this.

Thunderbird I copy (not move) all emails to a Local Folders Inbox. I then have a folder structure under that local folders Inbox. I click a run rules button and it moves them (not copies) to the relevant sub folder. The result is that apart from spam and legit emails without a rule, the inbox folder is emptied.

Outlook2010 I have the VBA routine that runs all rules in place and that works fine, I've even added the button to trigger that.

I have recreated my Thunderbird set-up by creating my folder structure under the Outlook Data File Inbox.

I've created for each email account a rule that all messages are copied (not moved) to that Outlook Data File Inbox.

I'm aware that rules must be created under each account and I believe no rules can be created in any Outlook Data File folder or sub folder.

However, if you then go to Rules/Alert pop up and select Run Rules Now you can select the rules to run and they will run on any folder including any Outlook Data File.

Essentially, I want to automate this process of running all rules on the Outlook Data File Inbox.

I cannot work out how to make the VBA code select that Outlook Data File Inbox, then run all rules on just that Outlook Data File Inbox.

Again, I believe this is necessary because if the Move rule runs from the account email inbox, that once the emails are moved from the account email inbox they are no longer available to be viewed on any other device.

I know I could copy all the emails from each account email inbox to the relevant sub folder and not bother copying to the Outlook Data File Inbox first. But this means I still need to regularly check all 8 email account inboxes in case an important email is in there for which I have not created a rule.

Any help would be appreciated.

Nigel

2 Answers2

0

I will not be able to help you with VBA but allow me to propose an alternative. First of all let me mention that it works for Outlook Data Files and any inbox that you specify. If you are familiar with VBA you should not have any problem with using my solution since the code is fairly simple.

Full solution has been described under similar question on superuser.

You can review it and clone it from Github project p0r. Its free.

To make it more relevant allow me to elaborate. I'm using Powershell to automate outlook and create custom rules within the script.

To connect to Outlook data file you can use following code:

$pstPath = "D:\path\to\pst\file.pst"     


# CREATING OUTLOOK OBJECT
$outlook = New-Object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")

# GETTING PST FILE THAT WAS SPECIFIED BY THE PSTPATH VARIABLE
$pst = $namespace.Stores | ?{$_.FilePath -eq $pstPath}

# ROOT FOLDER
$pstRoot = $pst.GetRootFolder()

# SUBFOLDERS
$pstFolders = $pstRoot.Folders

# PERSONAL SUBFOLDER
$personal = $pstFolders.Item("Personal")

And you can create your own rule by replacing the condition in the IF statement:

# MOVE EMAILS WITH SPECIFIC STRING IN TITLE TO THE SUBFOLDER /RANDOM/ UNDER PST FILE
# !      DESTINATION FOLDER SPECIFIED INLINE
    IF ($Email.Subject -match "SPECIFIC STRING IN TITLE") {
        $Email.Move($pstFolders.Item("Random")) | out-null
        display  ([string]$Email.Subject ) ([string]"Yellow")
        continue
    }

I'm using $Email.Move method to move email object from inbox to PST file, but you can use $Email.Copy if you prefer. Of course you can move emails between directories in Outlook data store as well.

Hope this helps. Let me know in case of any questions. I will be glad to help.

Community
  • 1
  • 1
mnmnc
  • 374
  • 3
  • 14
  • Thank you for your answer and apologies for not answering sooner. I have trying to sort out my emails and yours was lost in my mess. I haven't tried your idea yet but I will and then report back. Since asking that question I have updated to office 2013 so last month started using outlook 2013, so will see if your plan works with that. Really appreciate your input to this I've been surprised how little response I've had yours I think is the first! –  Dec 09 '14 at 18:44
0

Re: I cannot work out how to make the VBA code select that Outlook Data File Inbox...

Private Sub ProcessPST()

    Dim objNs As Namespace
    Dim pstFolder As folder
    Dim objItem As Object
    Dim i As Long

    Set objNs = GetNamespace("MAPI")
    Set pstFolder = objNs.Folders("Test") ' <--- Test is the name of the pst

    For i = 1 To pstFolder.Items.count
        Set objItem = pstFolder.Items(i)
        Debug.Print objItem.Subject
    Next i

ExitRoutine:
    Set objNs = Nothing
    Set pstFolder = Nothing
    Set objItem = Nothing

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52