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
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