質問編集履歴

1

全文の記載

2021/10/30 05:21

投稿

shunsuke_0319
shunsuke_0319

スコア2

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,93 @@
4
4
 
5
5
  なぜでしょうか?
6
6
 
7
+ エラーが出るのは
8
+
9
+
10
+
11
+ If CreateObject("Outlook.Application") Then です
12
+
13
+
14
+
15
+ Sub sample()
16
+
17
+ Const olMailItem = 0
18
+
19
+ Dim file As String
20
+
21
+ Dim pr As Presentation
22
+
23
+ Dim sl As Slide
24
+
25
+ Dim sh As Shape
26
+
27
+ Dim tb As Table
28
+
29
+ Dim r As Integer
30
+
31
+ Dim c As Integer
32
+
33
+ Dim s As String
34
+
35
+ Dim f1 As Boolean
36
+
37
+ Dim f2 As Boolean
38
+
39
+ Dim ol As Object
40
+
41
+ Dim mail As Object
42
+
43
+ Dim f As Object
44
+
45
+ Dim dic As Object
46
+
47
+ Dim k As Variant
48
+
49
+ Dim n As Variant
50
+
51
+
52
+
53
+ With Application.FileDialog(msoFileDialogOpen)
54
+
55
+ .Filters.Clear
56
+
57
+ .Filters.Add "ppt", "*.ppt?"
58
+
59
+ .InitialFileName = "C:\"
60
+
61
+ .AllowMultiSelect = False
62
+
63
+ If Not .Show Then Exit Sub
64
+
65
+ file = .SelectedItems(1)
66
+
67
+ End With
68
+
69
+ Do
70
+
71
+ Set pr = Presentations.Open(file)
72
+
73
+ For Each sl In pr.Slides
74
+
75
+ f1 = False
76
+
77
+ f2 = False
78
+
79
+ For Each sh In sl.Shapes
80
+
81
+ If sh.HasTable Then
82
+
83
+ Set tb = sh.Table
84
+
85
+ For r = 1 To tb.Rows.Count
86
+
87
+ For c = 1 To tb.Rows(r).Cells.Count
88
+
89
+ s = tb.Rows(r).Cells(c).Shape.TextFrame2.TextRange.Text
90
+
91
+ If InStr(s, "フレッツ") Then f1 = True
92
+
7
- If InStr(s, "専用") Then f1 = True
93
+ If InStr(s, "専用") Then f1 = True
8
94
 
9
95
  If InStr(s, "秋田") Then
10
96
 
@@ -28,8 +114,114 @@
28
114
 
29
115
  Next
30
116
 
117
+ MsgBox "無かった"
118
+
31
119
  Loop Until True
32
120
 
121
+ pr.Close
122
+
123
+ If Not (f1 And f2) Then Exit Sub
124
+
125
+ '
126
+
127
+ MsgBox "見つけた"
128
+
129
+ '添付ファイル
130
+
131
+ Set dic = CreateObject("Scripting.Dictionary")
132
+
133
+ With Application.FileDialog(msoFileDialogOpen)
134
+
135
+ .Filters.Clear
136
+
137
+ .Filters.Add "添付ファイル", "*.*"
138
+
139
+ .InitialFileName = "C:\"
140
+
141
+ .AllowMultiSelect = True
142
+
143
+ If Not .Show Then Exit Sub
144
+
145
+ file = .SelectedItems(1)
146
+
147
+ Set dic = CreateObject("Scripting.Dictionary")
148
+
149
+ Dim i As Integer
150
+
151
+ For i = 1 To .SelectedItems.Count
152
+
153
+ dic.Add .SelectedItems(i), Null
154
+
155
+ Next
156
+
157
+ End With
158
+
159
+ 'メール送信
160
+
161
+ With Application.FileDialog(msoFileDialogOpen)
162
+
163
+ .Filters.Clear
164
+
165
+ .Filters.Add "ppt", "*.ppt?"
166
+
167
+ .InitialFileName = "C:\"
168
+
169
+ .AllowMultiSelect = False
170
+
171
+ If Not .Show Then Exit Sub
172
+
173
+ file = .SelectedItems(1)
174
+
175
+ End With
176
+
177
+ Do
178
+
179
+ Set pr = Presentations.Open(file)
180
+
181
+ For Each sl In pr.Slides
182
+
183
+ f1 = False
184
+
185
+ f2 = False
186
+
187
+ For Each sh In sl.Shapes
188
+
189
+ If sh.HasTable Then
190
+
191
+ Set tb = sh.Table
192
+
193
+ For r = 1 To tb.Rows.Count
194
+
195
+ For c = 1 To tb.Rows(r).Cells.Count
196
+
197
+ s = tb.Rows(r).Cells(c).Shape.TextFrame2.TextRange.Text
198
+
199
+ If InStr(s, "専用") Then f1 = True
200
+
201
+ If InStr(s, "秋田") Then
202
+
203
+ If r <> tb.Rows.Count Then
204
+
205
+ If IsNumeric(tb.Rows(r + 1).Cells(c).Shape.TextFrame2.TextRange.Text) Then f2 = True
206
+
207
+ End If
208
+
209
+ End If
210
+
211
+ If f1 And f2 Then Exit Do
212
+
213
+ Next
214
+
215
+ Next
216
+
217
+ End If
218
+
219
+ Next
220
+
221
+ Next
222
+
223
+ Loop Until True
224
+
33
225
  If CreateObject("Outlook.Application") Then f1 = True
34
226
 
35
227
  If mail = ol.CreateItem(olMailItem) Then f1 = True
@@ -41,3 +233,141 @@
41
233
  mail.Subject = "件名"
42
234
 
43
235
  mail.Body = "本文"
236
+
237
+ For Each k In dic.keys
238
+
239
+ mail.Attachments.Add k
240
+
241
+ Next
242
+
243
+ Set dic = CreateObject("Scripting.Dictionary")
244
+
245
+ With Application.FileDialog(msoFileDialogOpen)
246
+
247
+ .Filters.Clear
248
+
249
+ .Filters.Add "添付ファイル", "*.*"
250
+
251
+ .InitialFileName = "C:\"
252
+
253
+ .AllowMultiSelect = True
254
+
255
+ If Not .Show Then Exit Sub
256
+
257
+ file = .SelectedItems(1)
258
+
259
+ Set dic = CreateObject("Scripting.Dictionary")
260
+
261
+ Dim l As Integer
262
+
263
+ For l = 1 To .SelectedItems.Count
264
+
265
+ dic.Add .SelectedItems(l), Null
266
+
267
+ Next
268
+
269
+ End With
270
+
271
+ mail.Attachments.Add file
272
+
273
+ Do
274
+
275
+ Set pr = Presentations.Open(file)
276
+
277
+ For Each sl In pr.Slides
278
+
279
+ f1 = False
280
+
281
+ f2 = False
282
+
283
+ For Each sh In sl.Shapes
284
+
285
+ If sh.HasTable Then
286
+
287
+ Set tb = sh.Table
288
+
289
+ For r = 1 To tb.Rows.Count
290
+
291
+ For c = 1 To tb.Rows(r).Cells.Count
292
+
293
+ s = tb.Rows(r).Cells(c).Shape.TextFrame2.TextRange.Text
294
+
295
+ If InStr(s, "フレッツ") Then f1 = True
296
+
297
+ If InStr(s, "秋田") Then
298
+
299
+ If r <> tb.Rows.Count Then
300
+
301
+ If IsNumeric(tb.Rows(r + 1).Cells(c).Shape.TextFrame2.TextRange.Text) Then f2 = True
302
+
303
+ End If
304
+
305
+ End If
306
+
307
+ Next
308
+
309
+ Next
310
+
311
+ End If
312
+
313
+ Next
314
+
315
+ Next
316
+
317
+ Loop Until True
318
+
319
+ Set ol = CreateObject("Outlook.Application")
320
+
321
+ Set mail = ol.CreateItem(olMailItem)
322
+
323
+ mail.Display
324
+
325
+ mail.To = "b230420" '宛先
326
+
327
+ mail.Subject = "件名"
328
+
329
+ mail.Body = "本文"
330
+
331
+ For Each n In dic.keys
332
+
333
+ mail.Attachments.Add n
334
+
335
+ 'ファイルを添付
336
+
337
+ Next
338
+
339
+ Set dic = CreateObject("Scripting.Dictionary")
340
+
341
+ With Application.FileDialog(msoFileDialogOpen)
342
+
343
+ .Filters.Clear
344
+
345
+ .Filters.Add "添付ファイル", "*.*"
346
+
347
+ .InitialFileName = "C:\"
348
+
349
+ .AllowMultiSelect = True
350
+
351
+ If Not .Show Then Exit Sub
352
+
353
+ file = .SelectedItems(1)
354
+
355
+ Set dic = CreateObject("Scripting.Dictionary")
356
+
357
+ Dim o As Integer
358
+
359
+ For o = 1 To .SelectedItems.Count
360
+
361
+ dic.Add .SelectedItems(o), Null
362
+
363
+ Next
364
+
365
+ End With
366
+
367
+ mail.Attachments.Add file
368
+
369
+ mail.Send '送信
370
+
371
+ ol.Quit
372
+
373
+ End Sub