Hey all!
I have installed and compiled a macro code with script that helps to automaticly extract attachments coming with new mail and preform a saving of the attachd file/s on a specific dir on the hard drive.
my machine is outlook 2002, running on windows xp.
it's goes like this:
[VBA]Sub GetAttachments(Item As Outlook.MailItem)
On Error GoTo GetAttachments_err
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0
For Each Atmt In Item.Attachments
FileName = "DIR_PATH" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit
Exit Sub
End Sub[/VBA]
In order to use this macro i have defined a rule that preformed every time that a new mail with attachment is recieved (and then it run the above script.).
My problem is that it doesnt work properly.
sometimes its work ok , but in many cases i get an
"The operation failed. An object could not be found" message.
i try to deal with it (including define a new profile - it didnt work.)
and try to run this script manually from the outlook by change the code line [VBA]Sub GetAttachments(Item As Outlook.MailItem)[/VBA]
to [VBA]Sub GetAttachments()[/VBA]
and define the variable item as an object in diferent line.
i tried to preform it on unread attachments messages in my inbox.
when i have tried this i got an "Object variable or With block variable not set" message.
As suggested in microsoft article i have read i try to redefine variable "item" as sugested : [VBA]Dim obj1 As Project1.Class1
Set obj1 = New Project1.Class1[/VBA]
but it didnt work.
any ideas from here?
thanks
yair