Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2014, 03:38 AM
smiler44 smiler44 is offline Niton could you help me again? Windows 7 64bit Niton could you help me again? Office 2010 64bit
Novice
Niton could you help me again?
 
Join Date: Nov 2014
Posts: 17
smiler44 is on a distinguished road
Default Niton could you help me again?

Niton,
I've put a special shout out for you as you have helped me so much on a macro on this forum at thread



https://www.msofficeforums.com/outlo...html#post73790 titled move emails from one folder to another.

I used your code in Excel 2007 and it is brilliant but I have moved it to another pc that uses Excel 2010 and the code fails at
Set searchItems = searchFolder.Items

full code is below

I have tried various things but can not get this line to be compatible with Excel 2010. Hoping you can come to my aid again.

thank you in advance

smiler44


Code:
Sub moveemail()
' In the Visual Basic Editor (VBE)
'  Tools menu | References...
'  Tick the entry for
'   Microsoft VBScript Regular Expressions 5.5
' &
' microsoft outlook 12.0 object libary
Dim nsNamespace As Outlook.Namespace
Dim objSourceFolder As Outlook.MAPIFolder
Dim moveToFolder As Outlook.MAPIFolder
Dim searchItems As Items
Dim msg As MailItem
Dim foundFlag As Boolean
Dim i As Long
Set NS = CreateObject("Outlook.Application").GetNamespace("MAPI")
On Error Resume Next    ' To bypass the error when the source folder is not found.
                        ' searchFolder will be Nothing
' Enter the exact names of the folders
' No slashes. Walk the path one folder at a time.
Set searchFolder = NS.Folders("Personal Folders").Folders("inbox").Folders("testin").Folders("testout")
Set moveToFolder = NS.Folders("Personal Folders").Folders("Drafts").Folders("testing").Folders("test")
On Error GoTo 0
If searchFolder Is Nothing Then
   MsgBox "Source folder not found!", vbOKOnly + vbExclamation, "searchSubject error"
   GoTo ExitRoutine
Else
   Debug.Print vbCr & "searchFolder: " & searchFolder
End If
Set searchItems = searchFolder.Items
For i = searchItems.Count To 1 Step -1
    If searchItems(i).Class = olMail Then
        Set msg = searchItems(i)
        pattern_abcd123456 msg, foundFlag
        If foundFlag = True Then
            Debug.Print " Move this mail: " & searchItems(i)
            MsgBox (searchItems(i))
            Call whattodonow
            searchItems(i).Move moveToFolder
        End If
    End If
Next
ExitRoutine:
    Set msg = Nothing
    Set searchItems = Nothing
    Set searchFolder = Nothing
    Set NS = Nothing
MsgBox ("all mail items checked")
End Sub

Sub patternabcd123456(MyMail As MailItem, fndFlag)
    Dim subj As String
    Dim re As Object
    Dim match As Variant
    fndFlag = False
    subj = MyMail.Subject
    Set re = CreateObject("vbscript.regexp")
    re.Pattern = "[a-z][a-z][a-z][a-z][0-9][0-9][0-9][0-9][0-9][0-9]"
    For Each match In re.Execute(subj)
        fndFlag = True
        Debug.Print vbCr & subj
        Debug.Print " *** Pattern found: " & match
    Next
End Sub
Reply With Quote
  #2  
Old 11-22-2014, 01:07 PM
smiler44 smiler44 is offline Niton could you help me again? Windows 7 64bit Niton could you help me again? Office 2010 64bit
Novice
Niton could you help me again?
 
Join Date: Nov 2014
Posts: 17
smiler44 is on a distinguished road
Default

ha, solved this. it was to do with the location in the code where
Set searchItems = searchFolder.Items sat I have moved in down a bit and it seems to work.
don't understand why Excel 2010 was unhappy yet 2007 was happy with the location

ho hum

smiler44

Last edited by smiler44; 11-22-2014 at 01:08 PM. Reason: additional information
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 01:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft