質問編集履歴

1

コードの追記とエラー発生場所

2021/10/05 23:07

投稿

xiamuji
xiamuji

スコア0

test CHANGED
File without changes
test CHANGED
@@ -6,6 +6,138 @@
6
6
 
7
7
  と表示されました。
8
8
 
9
+ コードは以下の通りです。
10
+
11
+ エラーが出たのはapp.workbooks.open(objItem.buf)です。
12
+
13
+
14
+
15
+
16
+
17
+ Dim i As Long, mCount As Long, MaxCount As Long, eMailName As String, j As Long
18
+
19
+ Dim myNamespace As NameSpace, app As Excel.Application
20
+
21
+ Dim outlook As Object
22
+
23
+ Dim myInbox As Object
24
+
25
+ Dim InboxFolder As Variant
26
+
27
+ Dim myItem As outlook.MailItem
28
+
29
+ Dim objIns As Inspector, objItem As Object, objAttachments As Object
30
+
31
+ Dim buf As String
32
+
33
+
34
+
35
+ Set outlook = CreateObject("Outlook.Application")
36
+
37
+ Set app = CreateObject("excel.application")
38
+
39
+ Set myNamespace = outlook.GetNamespace("MAPI")
40
+
41
+ Set InboxFolder = myNamespace.GetDefaultFolder(6)
42
+
43
+
44
+
45
+ app.Visible = True
46
+
47
+
48
+
49
+ mCount = InboxFolder.Items.Count
50
+
51
+ If mCount > 200 Then
52
+
53
+ MaxCount = mCount - 200
54
+
55
+ Else
56
+
57
+ MaxCount = 1
58
+
59
+ End If
60
+
61
+
62
+
63
+ For i = mCount To MaxCount Step -1
64
+
65
+
66
+
67
+ eMailName = InboxFolder.Items(i).Subject
68
+
69
+
70
+
71
+ If InboxFolder.Items(i).UnRead = True Then
72
+
73
+ If InStr(eMailName, "依頼書送付") > 0 Or _
74
+
75
+ InStr(eMailName, "連絡書送付") > 0 Then
76
+
77
+
78
+
79
+ Set myItem = InboxFolder.Items(i)
80
+
81
+
82
+
83
+ myItem.Display
84
+
85
+
86
+
87
+ Set objIns = Application.ActiveInspector
88
+
89
+ Set objItem = objIns.CurrentItem
90
+
91
+ For j = 1 To objItem.Attachments.Count
92
+
93
+ Debug.Print objItem.Attachments(j)
94
+
95
+ buf = objItem.Attachments(j)
96
+
97
+ Debug.Print Dir(objItem.Attachments(j))
98
+
99
+ If InStr(buf, "xlsm") Then
100
+
101
+ ⇒ app.Workbooks.Open (objItem.buf)
102
+
103
+ End If
104
+
105
+ Next j
106
+
107
+ End If
108
+
109
+ End If
110
+
111
+
112
+
113
+ Next i
114
+
115
+
116
+
117
+ Set myItem = Nothing
118
+
119
+ Set outlook = Nothing
120
+
121
+ Set app = Nothing
122
+
123
+ Set myNamespace = Nothing
124
+
125
+ Set InboxFolder = Nothing
126
+
127
+ Set objIns = Nothing
128
+
129
+ Set objItem = Nothing
130
+
131
+ Set objAttachments = Nothing
132
+
133
+
134
+
135
+ End Sub
136
+
137
+
138
+
139
+
140
+
9
141
  メールは受信トレイの中にあり、メールの特定はできています。
10
142
 
11
143
  メールに添付されたファイルの保存先の特定はどうすれば良いのでしょうか。