Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VBScript
Hello,
I found the following script but i get a runtime error 13 type mismatch on the line that says "Set olMi = Fldr.Items(i)" Thanks for your help.
Sub SaveAttachments()
 
<pre>
Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim MoveToFldr As MAPIFolder
Dim olMi As MailItem
Dim olAtt As Attachment
Dim MyPath As String
Dim i As Long
 
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set MoveToFldr = Fldr.Folders("CompSurv")
MyPath = "C:\My Documents\Completed Survey\"
 
For i = Fldr.Items.Count To 1 Step -1
    Set olMi = Fldr.Items(i)
    If InStr(1, olMi.Subject, "Completed Survey") &gt; 0 Then
        For Each olAtt In olMi.Attachments
            If olAtt.FileName = "Test.xls" Then
                olAtt.SaveAsFile MyPath & olMi.SenderName & ".xls"
            End If
        Next olAtt
        olMi.Save
        olMi.Move MoveToFldr
    End If
Next i
 
Set olAtt = Nothing
Set olMi = Nothing
Set Fldr = Nothing
Set MoveToFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub
Posted 26-Mar-13 7:01am
namerg408
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try: Dim olMi As Variant
  Permalink  
Comments
namerg at 26-Mar-13 13:58pm
   
@Zoltán: PERFECT. But when saving the attachment, it saves it as my profile name, not the attachment name, i did send the attachment as Test.xlsx
Zoltán Zörgő at 26-Mar-13 14:02pm
   
You wrote this: olAtt.SaveAsFile MyPath & olMi.SenderName & ".xls", so if you sent this mail to yourself, the file name will be yours. Just a note: I suggest, you normalize the SenderName before using it in a file name.
namerg at 26-Mar-13 14:21pm
   
Got it. I did replace that line with olAtt.SaveAsFile MyPath & olAtt.FileName
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try:
For i = (Fldr.Items.Count-1) To 0 Step -1
       Set olMi = Fldr.Items(i)
Type mismatch means that the object returned does not match what you are setting to.

If above does not resolve, do JavaScript debugging and see for what value and when is the error happening. Try to look around that and troubleshoot.
  Permalink  
Comments
namerg at 26-Mar-13 14:36pm
   
Thanks Sandeep

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210


Advertise | Privacy | Mobile
Web01 | 2.8.150331.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100