Via de onderstaande code probeer ik de attachment van een mailtje in een bepaalde outlook folder op te slaan. Alleen krijg ik dit niet voor elkaar. Ik weet dat alle attachments ook weer mailtjes zijn. Dus die zouden met gemak in de outlook folder opgeslagen moeten kunnen worden.
Kan iemand mij uit de brand helpen.
Kan iemand mij uit de brand helpen.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
| Sub extract()
Dim oApp As Application
Dim oNS As NameSpace
Dim oMsg As Object
Dim oAttachments As Outlook.Attachments
Dim oAttachment As Object
Dim oNewMail As MailItem
Dim oMailItem As MailItem
Dim oObject As Object
Dim oSubAttachment As Object
Dim oItem As Items 'use as subattachment in this
Dim strControl
Set oApp = New Outlook.Application
Set oNS = oApp.GetNamespace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
Set myFolder = oFolder.Folders("Test")
Set myFolderTooDeep = myFolder.Folders("Test too deep")
Set myFolderDone = myFolder.Folders("Test done")
Set myFolderNoAtt = myFolder.Folders("Test attachment")
strControl = 0
For Each oMsg In myFolder.Items 'oMsg is an item
With oMsg 'oMsg has attachments or attachmet
Debug.Print oMsg.Attachments.Count
If (oMsg.Attachments.Count > 0) Then
For Each oAttachment In oMsg.Attachments
'an attachments or an attachment
With oAttachment
mytype = oAttachment.Type
toodeep = 0
If (mytype = 1) Then
'a file with a name
strControl = strControl + 1
oAttachment.SaveAsFile _
"c:\" _
& strControl & oAttachment.FileName
ElseIf (mytype = 5) Then
'Hier moet het mailtje in een andere folder gesaved worden.
Set oNewMail = oAttachment
oNewMail.Move myFolderTooDeep
End If
End With
Next
If toodeep = 0 Then
oMsg.Move myFolderDone
'saved all attachments - move this mail to done
End If
Else
oMsg.Move myFolderNoAtt
End If
End With
Next
End Sub |