No announcement yet.

problems with running of auto attachments saving macro

  • Filter
  • Time
  • Show
Clear All
new posts

  • problems with running of auto attachments saving macro

    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:

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

    Sub GetAttachments(Item As Outlook.MailItem) to Sub GetAttachments()

    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 :

    Dim obj1 As Project1.Class1
    Set obj1 = New Project1.Class1

    but it didnt work.

    any ideas from here?

    Last edited by wullieb1; 19th January 2009, 01:00.

  • #2
    Re: problems with running of auto attachments saving macro

    Edited post to wrap code in code tags.