Having some trouble with a run-a-script rule (moving mail based on file type)

Post number 3 has been selected as the best answer.

Status
Not open for further replies.

EricSigh

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Hi, sorry if I'm in the wrong place for this, but I've been trying to implement the advice in this article:


Here is the slightly altered code I'm using:

Code:
Sub MoveMail(Item As Outlook.MailItem)


If Item.Attachments.Count > 0 Then


Dim attCount As Long
Dim strFile As String
Dim sFileType As String


attCount = Item.Attachments.Count


For i = attCount To 1 Step -1
      strFile = Item.Attachments.Item(i).FileName
      
      sFileType = LCase$(Right$(strFile, 4))
    
    Select Case sFileType
        Case ".xml"
    ' do something if the file types are found 
    ' this code moves the message
      Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Test"))
    
   ' stop checking if a match is found and exit sub
       GoTo endsub
      End Select
  Next i


End If
 
endsub:


  Set Item = Nothing
 
End Sub



I know the author recommends using a stub-macro in order to get the rule to run, I'm just not quite sure where to implement that. Any help is appreciated!
 
Sorry I didn't specify, but when I run the rule it just seems like nothing happens.
 
Add this macro to the same module as the script then select a message the rule should apply to and run this macro to see if it works.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
MoveMail objItem

End Sub

make sure the folder you are moving the message to exists - Is there a subfolder called test in the inbox?
 
Add this macro to the same module as the script then select a message the rule should apply to and run this macro to see if it works.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
MoveMail objItem

End Sub

make sure the folder you are moving the message to exists - Is there a subfolder called test in the inbox?
Thank you! This immediately fixed it haha, sorry I'm not super familiar with VB. Yes, I created a test folder on my computer to try a few things, it will be changed when I implement this on a user's computer. Follow up question, will this also work for a subfolder within a subfolder? And if so what would the syntax be?

Say I have a test 2 folder within my test folder, I've tried

Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Test 2"))

and

Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Test").Folders("Test 2"))


I'll be looking for more info on that on slipstick, but thank you for your help so far!
 
Thank you! This immediately fixed it haha, sorry I'm not super familiar with VB. Yes, I created a test folder on my computer to try a few things, it will be changed when I implement this on a user's computer. Follow up question, will this also work for a subfolder within a subfolder? And if so what would the syntax be?

Say I have a test 2 folder within my test folder, I've tried

Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Test 2"))

and

Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Test").Folders("Test 2"))


I'll be looking for more info on that on slipstick, but thank you for your help so far!

Nevermind, I was able to figure it out. Thank you so much for your help!
 
Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Test").Folders("Test 2"))
This is the one (but it has an extra ')' ) if the folders are
Inbox'
-- Test
---- Test 2

the first would be used if there were two folders at the same level under the inbox.
Inbox
-- Test
-- Test 2
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Trying to get old emails from a not working computer but having trouble. Using Outlook 6
M having trouble importing excel data into outlook contacts BCM (Business Contact Manager) 1
R Outlook 2021 Having problem setting up outlook 2021 with windows 11. I have 3 gmail accounts and I want the 3 gmail, emails to merge into the same outlook input. Using Outlook.com accounts in Outlook 0
e_a_g_l_e_p_i Is anyone else having problem conneccting to gmail? Using Outlook 27
N Having Shared Calendar shift to Current day Using Outlook 0
dbjdbj Is it only me having a fun time with Outlook.com "beta" ? Using Outlook 3
O Importing Mbox - anyone out there having experience with this tool... Using Outlook 2
A Outlook 2019 having issues with 'people search' and not making suggestions in email To: etc Using Outlook 12
M I'm Having problems Moving Contacts to a New List Using Outlook 8
O Having rules run on old mails noved to inbox Outlook VBA and Custom Forms 8
V Problem not having Contacts folder after importing emails from Yahoo. Using Outlook 0
J outlook having sort by date or from unable to display sender name. Using Outlook 2
M Having Calander send E-mails Using Outlook 3
B Having Recent Issues with Hotmail Connector? Using Outlook.com accounts in Outlook 17
O Exchange 2003 displaying HTML emails as having attachments Exchange Server Administration 7
T Get rid of having to type verification characters to send mail BCM (Business Contact Manager) 2
A Contact Manager Unable to Initialize...after having tested Office BCM (Business Contact Manager) 1
N Trouble with server names Using Outlook 1
G Trouble with Office 365/2016 Using Outlook 3
M Trouble using keyboard shortcut for color categories in Outlook 2016 Using Outlook 3
M Trouble downloading Outlook on an Android phone Using Outlook 4
B Trouble Starting Outlook 2010 after Crash Using Outlook 3
U Trouble migrating Contacts (2002) to People (2013) Using Outlook 3
K New to BCM - trouble importing contacts & accounts BCM (Business Contact Manager) 3
makinmyway Trouble Installing BCM Outlook 2013; Endless Install Loop Happens Using Outlook 0
M Trouble Importing folders from Outlook 2007 to Outlook 2013 Using Outlook 12
S trouble with Outlook 2010 saving sent emails Using Outlook 2
B Trouble Locating Tools Menu since There's No Standard Toolbar in Office 2010 Using Outlook 1
T Outlook 2007 - trouble with alphabetizing when titles are used (ie - Mr.) Using Outlook 0
M Outlook 2010 stuck in Work Offline mode; trouble sending email Using Outlook 1
A Trouble importing data to radio buttons Business Contact Manager 2010 (BCM) Using Outlook 2
B Trouble Adding @Outlook.com Email Accounts Using Outlook 3
A emails disappearing from inbox outlook 2010 exchange server 2010 major trouble Exchange Server Administration 6
K Trouble converting the ANSI PST to a Unicode PST Using Outlook 4
V Trouble Running Outlook 2007 and 2010 Using Outlook 4
U Trouble for sharing Calendar Using Outlook 3
S Trouble setting up Outlook Connector to sync with windows live Using Outlook.com accounts in Outlook 3
T Trouble with creating database BCM (Business Contact Manager) 1
K Trouble using SaveAs Outlook VBA and Custom Forms 3
M trouble connection to remote database BCM (Business Contact Manager) 1
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
V Outlook macros no longer run until VB editor is opened Outlook VBA and Custom Forms 0
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
N Outlook 2021 'Run Script" Rules? Outlook VBA and Custom Forms 4
T Outlook 2010 Errore run-time -2147417851 (80010105) Metodo delete ContactItem non riuscito Outlook VBA and Custom Forms 0
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
G Save attachment run a script rule Outlook VBA and Custom Forms 0
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
D Outlook 2013 Macros only run in VB editor, not in drop down or button Outlook VBA and Custom Forms 14

Similar threads

Back
Top