Move Email with Attachment to Folder

drivetheory

Member
Outlook version
Outlook 2013 64 bit
Email Account
IMAP
Idk why this isn't working...

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 ".doc"
    ' do something if the file types are found
    ' this code moves the message
      Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("BADSTUFF"))
    
   ' stop checking if a match is found and exit sub
       GoTo endsub
      End Select
  Next i

End If
 
endsub:

  Set Item = Nothing
 
End Sub

it's basically the code verbatim from here:

But for whatever reason i can't test it in the VBA editor window, and when I add it to a rule it still doesn't do anything.

what am I doing wrong?

outlook-hates-me.png
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you need to use a 'stub macro' to test the rule manually.

Select a message and run this macro -

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

In VBE's tools > options > general - is it set to break on all unhandled errors?
 

saurabhjha

New Member
Outlook version
Outlook on the web
Email Account
Exchange Server
Hello,
  • firstly, create a folder
  • Open the mail
  • Download the attachments
  • then select the downloaded file to desire location
 

jessewalter375

New Member
Outlook version
Outlook 2019 64-bit
Email Account
Exchange Server 2013
To save the attachments, follow these general steps:

1.Select the message or open the message in its own window.

2.Double-click a message in the Inbox to open it in its own window.

3.Choose File→Save Attachments from the menu.

4.The command may be subtly different, depending on your e-mail program, but generally it’s found on the File menu.

5.Use the dialog box to find a location for the file.

6.Use the Browse button to change the folder location.

7.Click the Save button to save the attachment.

Hope this is helpful to you.
 
Similar threads
Thread starter Title Forum Replies Date
D Delete an email with a video attachment. I can't delete or move it. System shows "not responding" wi Using Outlook 2
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
L Making rule to move email to folder from one O365 domain Using Outlook 1
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
acpete48317 Categorize and move Outlook Email Outlook VBA and Custom Forms 2
S Move email accounts to new laptop Using Outlook 1
Diane Poremsky Create Tasks from Email and move to different Task folders New Slipstick.com Articles 0
O VBA Move EMail Outlook VBA and Custom Forms 3
P Move email to folder Using Outlook 1
P move a specified email "From" tag items to a certain folder whenever there is "New Mail" in the inbo Outlook VBA and Custom Forms 5
G email returns after running macro to move emails Outlook VBA and Custom Forms 1
C Outlook 2013 - Email Gets Sent - But Does Not Move From Outbox to Sent Box Using Outlook 4
D Move email to same folder as the rest of the conversation Using Outlook 1
G Outlook 2003 I need to move email to folder based on subject, using wild card Using Outlook 0
K Outlook Cached Mode - can't create rules to move email to another mailbox Using Outlook 2
D User cannot move email messages within Outlook Inbox folder and sub-folders. Using Outlook 0
S Rule to move BCC email to a folder Using Outlook 6
E error code MAPI error 0x80040107. I'm trying to move email messages and email lists from my old MS Using Outlook 2
B Move some email to different folder in Outlook Using Outlook 1
B Move Sent Email to archival pst folder and mark as read - HOW TO Outlook VBA and Custom Forms 2
V move read email based on date and sender Outlook VBA and Custom Forms 6
V Move email using the Close event Outlook VBA and Custom Forms 11
GregS Outlook 2016 Move Outlook to new computer? Using Outlook 2
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 4
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
G Cannot Move Autocomplete File to New Computer Using Outlook 15
M Move to Folder Using Outlook 1
P Move emails between 2 mailboxes. Using Outlook 0
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
T Move calendar invites to new calendar Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
I Automating message move between folders Outlook VBA and Custom Forms 0
K Outlook Rules: Move a Copy Using Outlook 4
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
N Move emails of same conversation to same subfolder Using Outlook 6

Similar threads

Top