A
adimax
Alright, I've asked several times about this project I'm working on
and I've got some great help here. I've also done a bit of searching
and researching, and I'm stumped. I like how most of this executes,
but there is a problem with it:
The code is setup to go off on a Rule created that states when email
with XXX comes in, execute code. The problem is, it executes the code
on the currently selected email, whether that was the email that came
in and triggered the rule or not.
What I'd like is a way for the code/rule to work together and go off
on the email that comes in and ONLY that email. Whether that is or can
be done from the Inbox with the Rule detecting XXX, or if I need a
separate rule that moves the email into another folder, which then
fires off. Either way, I'm at a loss for where to start with that
code.
I hope this makes sense and anyone out there can make sense of what
I've got below.
As always, thanks very, very much in advance and for any help you can
offer.
Benjamin
---
Full Code:
Sub SaveRecording(MyMail As MailItem)
On Error Resume Next
'Declarations
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myFin As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim objFolder1 As Outlook.MAPIFolder, objFolder2 As
Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder1 = objInbox.Parent.Folders("[Saved]")
Set objFolder2 = objInbox.Parent.Folders("[Unsaved]")
'Destination folder for saved files
myOrt = "W:\"
'Process the selected item
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
'Start Process
For Each myItem In myOlSel
'Attachments
Set myAttachments = myItem.Attachments
'Check
If myAttachments.Count > 0 Then
'Do the following
For i = 1 To myAttachments.Count
'If myAttachments(i).Item.Size < 2 Then
StartPrompt:
myFin = InputBox("Please type a filename below. You do not have to
include the .wav extension:", "Saving recording...", "")
If myFin = "" Then
myItem.UnRead = True
myItem.Move objFolder2
Exit Sub
End If
'Save to destionation folder
myAttachments(i).SaveAsFile myOrt & _
myFin & ".wav"
myItem.UnRead = False
myItem.Move objFolder1
Next i
End If
Next
'free variables
Set myItems = Nothing
Set myItem = Nothing
Set myAttachments = Nothing
Set myAttachment = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing
End Sub
and I've got some great help here. I've also done a bit of searching
and researching, and I'm stumped. I like how most of this executes,
but there is a problem with it:
The code is setup to go off on a Rule created that states when email
with XXX comes in, execute code. The problem is, it executes the code
on the currently selected email, whether that was the email that came
in and triggered the rule or not.
What I'd like is a way for the code/rule to work together and go off
on the email that comes in and ONLY that email. Whether that is or can
be done from the Inbox with the Rule detecting XXX, or if I need a
separate rule that moves the email into another folder, which then
fires off. Either way, I'm at a loss for where to start with that
code.
I hope this makes sense and anyone out there can make sense of what
I've got below.
As always, thanks very, very much in advance and for any help you can
offer.
Benjamin
---
Full Code:
Sub SaveRecording(MyMail As MailItem)
On Error Resume Next
'Declarations
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOrt As String
Dim myFin As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim objFolder1 As Outlook.MAPIFolder, objFolder2 As
Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder1 = objInbox.Parent.Folders("[Saved]")
Set objFolder2 = objInbox.Parent.Folders("[Unsaved]")
'Destination folder for saved files
myOrt = "W:\"
'Process the selected item
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
'Start Process
For Each myItem In myOlSel
'Attachments
Set myAttachments = myItem.Attachments
'Check
If myAttachments.Count > 0 Then
'Do the following
For i = 1 To myAttachments.Count
'If myAttachments(i).Item.Size < 2 Then
StartPrompt:
myFin = InputBox("Please type a filename below. You do not have to
include the .wav extension:", "Saving recording...", "")
If myFin = "" Then
myItem.UnRead = True
myItem.Move objFolder2
Exit Sub
End If
'Save to destionation folder
myAttachments(i).SaveAsFile myOrt & _
myFin & ".wav"
myItem.UnRead = False
myItem.Move objFolder1
Next i
End If
Next
'free variables
Set myItems = Nothing
Set myItem = Nothing
Set myAttachments = Nothing
Set myAttachment = Nothing
Set myOlApp = Nothing
Set myOlExp = Nothing
Set myOlSel = Nothing
End Sub