Print attachments automatically and move the mail to an existing folder called "Ted"

PamBeesly

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
I'm very new to VBA and I'm hoping someone can help me with a script that moves an email from say 10 different senders to a specific folder called "ted" for example.

I have a working rule with the script enabled which prints the email attachments automatically, but when ever I try to make an additional rule to move the emails from those 10 senders to a folder called "ted" it breaks the autoprint script. No error message, just nothing happens.

Can someone help me add a piece of script to my existing one that will move the received emails after the attachment has been printed to the folder called "ted"?

Here is the script that works for emails that only go to my inbox


' Script to run with an Outlook rule.
' Open Visual Basic windows in Outlook,
' and paste the entirety of this script
' into the ThisOutlookSession window.
' Save the script and close-and-reopen
' Outlook to test.


Sub AttachmentPrint(Item As Outlook.MailItem)

On Error GoTo OError

' This script finds the system's Temp folders,
' saves any attachments, and runs the Print
' command for that file.

Dim oFS As FileSystemObject
Dim sTempFolder As String
Set oFS = New FileSystemObject
sTempFolder = oFS.GetSpecialFolder(TemporaryFolder)

sTmpFld = sTempFolder & "\OETMP" & Format(Now, "yyyymmddhhmmss")
MkDir (sTmpFld)

' in the next few lines, you'll see an entry that
' says FileType = . This line gets the last 4
' characters of the file name, which we'll use later.

Dim oAtt As Attachment
For Each oAtt In Item.Attachments
FileName = oAtt.FileName
FileType = LCase$(Right$(FileName, 4))
FullFile = sTmpFld & "\" & FileName
oAtt.SaveAsFile (FullFile)

' We're using the FileType text. Note that it's the
' last 4 characters of the file name, which is why
' the next chunk has .xls and xlsx (without the period)
' - the period counts as the fourth character.

Select Case FileType
Case ".doc", "docx", ".xls", "xlsx", ".ppt", "pptx", ".pdf", ".tif"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(0)
Set objFolderItem = objFolder.ParseName(FullFile)
objFolderItem.InvokeVerbEx ("print")
End Select
Next oAtt

If Not oFS Is Nothing Then Set oFS = Nothing
If Not objFolder Is Nothing Then Set objFolder = Nothing
If Not objFolderItem Is Nothing Then Set objFolderItem = Nothing
If Not objShell Is Nothing Then Set objShell = Nothing

OError:
If Err <> 0 Then
MsgBox Err.Number & " - " & Err.Description
Err.Clear
End If

Exit Sub
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you can try using

Dim objNS As Outlook.NameSpace
Dim objTedFolder As Outlook.Folder
Set objNS = Application.GetNamespace("MAPI")

'Ted is a subfolder of Inbox
Set objTedFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("Ted")
item.move ojbTedFolder

put it at the end, after the print
 

PamBeesly

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
you can try using

Dim objNS As Outlook.NameSpace
Dim objTedFolder As Outlook.Folder
Set objNS = Application.GetNamespace("MAPI")

'Ted is a subfolder of Inbox
Set objTedFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("Ted")
item.move ojbTedFolder

put it at the end, after the print
First off, thank you for your response but I cant get it to work. I get an error saying object not found. Can you tell me exactly where this folder move script should go relative to my existing script?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I would put it after
End Select
Next oAtt

But... because attachments are slow and vba fast, not sure how well it will work. I'll try and test it this evening.
 

PamBeesly

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
I tried doing that but I was still unable to get it to work.

Any other suggestions?

Thanks,
 
Similar threads
Thread starter Title Forum Replies Date
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
I Print Automatically Attachments Outlook VBA and Custom Forms 3
C automatically print attachments Using Outlook 4
5 Automatically print email attachments Using Outlook 7
M Print email and, attachments sent in hyperlinks in the email Outlook VBA and Custom Forms 2
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
J Auto print PDF attachments as they arrive with certain words in subject Outlook VBA and Custom Forms 3
M Print Attachments from another mailbox (not default) Outlook VBA and Custom Forms 2
O For Outlook 2007 - VBA to print attachments Using Outlook 1
J Outlook 2010 using Quick Print to print attachments Using Outlook 1
A Outlook 11 for Mac won't print e-mail attachments Using Outlook 6
P Possible to write a macro to print all attachments with specific . Outlook VBA and Custom Forms 1
Z Re: Auto Print email and word attachments on send Outlook VBA and Custom Forms 1
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
S CONTACT FIELD PRINT ORDER Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
M Batch print without appended trail of repeated e Using Outlook 2
witzker print-list-of-outlook-folders with sort posibility Outlook VBA and Custom Forms 7
M Custom Calendar Print Suggestions? Using Outlook 0
A Day view - print appointment details Using Outlook 1
I print calendar without subject and details Using Outlook 1
oliv- property "is printed" or catching print events Outlook VBA and Custom Forms 2
Diane Poremsky Print a list of your Outlook folders Using Outlook 0
Diane Poremsky Combine and Print Multiple Outlook Calendars Using Outlook 0
B Print list of previously sent recipients Using Outlook 1
R Print email message and attachment in order Outlook VBA and Custom Forms 2
L Outlook 2002: HTML Emails Will Not Print: Please Help Using Outlook 0
A Print first page of a new email Outlook VBA and Custom Forms 7
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
Diane Poremsky No drop down calendars in Outlook 2010 Print Options Using Outlook 0
Diane Poremsky Print Monthly or Work Week Calendars Using Outlook 0
S Macro to print & move selected emails? Using Outlook 3
H Problems With Outlook 2013 VBA To Send and Print an email Outlook VBA and Custom Forms 1
D Outlook 2013 Categories won't print In color Using Outlook 2
G Calendar monthly view - Print just 3 weeks Using Outlook 5
R Can't modify Outlook view font with IE anymore (even though IE still affects print font) Using Outlook 5
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
L Outlook 2010 Quick Print Attachment, nothing happend Using Outlook 0
J Automatically Print PDF When They Are Received Using Outlook 4
M button to send and print emails Using Outlook 26
S How to print ONLY first line of appointments in month view? Using Outlook 1
M print free/busy schedule of an user Using Outlook 2
W Cannot print Outlook 2007 emails Using Outlook 2
R problem with incomming e-mail I am unable to print full e-mail letter Using Outlook 1
M Custom print contacts Using Outlook 2
E Can't print from Outlook on wifi network Using Outlook 0
E can't print some retail discount coupons Using Outlook 7
J calendar print setup in outlook 2010 Using Outlook 1
D Use Outlook 2003 embedded imaged cannot print from the mail preview list Using Outlook 4

Similar threads

Top