専用で秋田のときにaquarius0319
フレッツで秋田のときにb230420にメールを送れるようにしたいのですがこれだとaquarius0319にしかメールがいきません
なぜでしょうか?
Sub sample()
Const olMailItem = 0
Dim file As String
Dim pr As Presentation
Dim sl As Slide
Dim sh As Shape
Dim tb As Table
Dim r As Integer
Dim c As Integer
Dim s As String
Dim f1 As Boolean
Dim f2 As Boolean
Dim ol As Object
Dim mail As Object
Dim f As Object
Dim dic As Object
Dim k As Variant
Dim n As Variant
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "ppt", ".ppt?"
.InitialFileName = "C:"
.AllowMultiSelect = False
If Not .Show Then Exit Sub
file = .SelectedItems(1)
End With
Do
Set pr = Presentations.Open(file)
For Each sl In pr.Slides
f1 = False
f2 = False
For Each sh In sl.Shapes
If sh.HasTable Then
Set tb = sh.Table
For r = 1 To tb.Rows.Count
For c = 1 To tb.Rows(r).Cells.Count
s = tb.Rows(r).Cells(c).Shape.TextFrame2.TextRange.Text
If InStr(s, "フレッツ") Then f1 = True
If InStr(s, "専用") Then f1 = True
If InStr(s, "秋田") Then
If r <> tb.Rows.Count Then
If IsNumeric(tb.Rows(r + 1).Cells(c).Shape.TextFrame2.TextRange.Text) Then f2 = True
End If
End If
If f1 And f2 Then Exit Do
Next
Next
End If
Next
Next
MsgBox "無かった"
Loop Until True
pr.Close
If Not (f1 And f2) Then Exit Sub
'
MsgBox "見つけた"
'添付ファイル
Set dic = CreateObject("Scripting.Dictionary")
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "添付ファイル", "."
.InitialFileName = "C:"
.AllowMultiSelect = True
If Not .Show Then Exit Sub
file = .SelectedItems(1)
Set dic = CreateObject("Scripting.Dictionary")
Dim i As Integer
For i = 1 To .SelectedItems.Count
dic.Add .SelectedItems(i), Null
Next
End With
'メール送信
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "ppt", ".ppt?"
.InitialFileName = "C:"
.AllowMultiSelect = False
If Not .Show Then Exit Sub
file = .SelectedItems(1)
End With
Do
Set pr = Presentations.Open(file)
For Each sl In pr.Slides
f1 = False
f2 = False
For Each sh In sl.Shapes
If sh.HasTable Then
Set tb = sh.Table
For r = 1 To tb.Rows.Count
For c = 1 To tb.Rows(r).Cells.Count
s = tb.Rows(r).Cells(c).Shape.TextFrame2.TextRange.Text
If InStr(s, "専用") Then f1 = True
If InStr(s, "秋田") Then
If r <> tb.Rows.Count Then
If IsNumeric(tb.Rows(r + 1).Cells(c).Shape.TextFrame2.TextRange.Text) Then f2 = True
End If
End If
If f1 And f2 Then Exit Do
Next
Next
End If
Next
Next
Loop Until True
Set ol = CreateObject("Outlook.Application")
Set mail = ol.CreateItem(olMailItem)
mail.Display
mail.To = "aquarius0319" '宛先
mail.Subject = "件名"
mail.Body = "本文"
For Each k In dic.keys
mail.Attachments.Add k
Next
Set dic = CreateObject("Scripting.Dictionary")
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "添付ファイル", "."
.InitialFileName = "C:"
.AllowMultiSelect = True
If Not .Show Then Exit Sub
file = .SelectedItems(1)
Set dic = CreateObject("Scripting.Dictionary")
Dim l As Integer
For l = 1 To .SelectedItems.Count
dic.Add .SelectedItems(l), Null
Next
End With
mail.Attachments.Add file
mail.Send '送信
ol.Quit
Do
Set pr = Presentations.Open(file)
For Each sl In pr.Slides
f1 = False
f2 = False
For Each sh In sl.Shapes
If sh.HasTable Then
Set tb = sh.Table
For r = 1 To tb.Rows.Count
For c = 1 To tb.Rows(r).Cells.Count
s = tb.Rows(r).Cells(c).Shape.TextFrame2.TextRange.Text
If InStr(s, "フレッツ") Then f1 = True
If InStr(s, "秋田") Then
If r <> tb.Rows.Count Then
If IsNumeric(tb.Rows(r + 1).Cells(c).Shape.TextFrame2.TextRange.Text) Then f2 = True
End If
End If
Next
Next
End If
Next
Next
Loop Until True
Set ol = CreateObject("Outlook.Application")
Set mail = ol.CreateItem(olMailItem)
mail.Display
mail.To = "b230420" '宛先
mail.Subject = "件名"
mail.Body = "本文"
For Each n In dic.keys
mail.Attachments.Add n
'ファイルを添付
Next
Set dic = CreateObject("Scripting.Dictionary")
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "添付ファイル", "."
.InitialFileName = "C:"
.AllowMultiSelect = True
If Not .Show Then Exit Sub
file = .SelectedItems(1)
Set dic = CreateObject("Scripting.Dictionary")
Dim o As Integer
For o = 1 To .SelectedItems.Count
dic.Add .SelectedItems(o), Null
Next
End With
mail.Attachments.Add file
mail.Send '送信
ol.Quit
End Sub
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。