J
Jamie
Hi there,
I am trying to write a macro that will search my outlook inbox for a
specific subject heading then save the attatchment to a specific folder.
I have picked up this code with help from this site but my VBA skills are
extremely limited and I can't get it to work. When I run it It stops at the
first line and gives this error message:
Compile error:
User-defined type not defined
Code:
Sub SaveAttachments()
Set myOLApp = CreateObject("Outlook.Application")
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("eisreq")
MyPath = "I:\EIS\Forms\"
For i = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "EIS") > 0 Then
For Each olAtt In olMi.Attachments
If olAtt.Filename = "EIS Request.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
Can anyone tell me what I'm doing wrong?
Any help would be greatfully appreciated.
Thanks in advance
Jamie
I am trying to write a macro that will search my outlook inbox for a
specific subject heading then save the attatchment to a specific folder.
I have picked up this code with help from this site but my VBA skills are
extremely limited and I can't get it to work. When I run it It stops at the
first line and gives this error message:
Compile error:
User-defined type not defined
Code:
Sub SaveAttachments()
Set myOLApp = CreateObject("Outlook.Application")
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("eisreq")
MyPath = "I:\EIS\Forms\"
For i = Fldr.Items.Count To 1 Step -1
Set olMi = Fldr.Items(i)
If InStr(1, olMi.Subject, "EIS") > 0 Then
For Each olAtt In olMi.Attachments
If olAtt.Filename = "EIS Request.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
Can anyone tell me what I'm doing wrong?
Any help would be greatfully appreciated.
Thanks in advance
Jamie