ExcelのVBAなんですがエクセルに専用と書いていても"無かった"と表示されてしまします
なぜでしょうか?
VBA
1Sub 最終sample() 2Const olMailItem = 0 3Dim file As String 4Dim pr As Workbook 5Dim sl As Worksheet 6Dim sh As Shape 7Dim tb As Table 8Dim r As Integer 9Dim c As Integer 10Dim s As String 11 12Dim f1 As Boolean 13Dim f2 As Boolean 14Dim ol As Object 15Dim mail As Object 16Dim f As Object 17Dim dic As Object 18Dim k As Variant 19Dim n As Variant 20Dim mailTo As String 21 22With Application.FileDialog(msoFileDialogOpen) 23.Filters.Clear 24.Filters.Add "xlsx", "*.xlsx?" 25.InitialFileName = "C:\" 26.AllowMultiSelect = False 27If Not .Show Then Exit Sub 28file = .SelectedItems(1) 29End With 30 31Do 32Set pr = Workbooks.Open(file) 33For Each sl In pr.Worksheets 34f1 = False 35f2 = False 36For Each sh In sl.Shapes 37If sh.HasTable Then 38Set tb = sh.Table 39For r = 1 To tb.Rows.Count 40For c = 1 To tb.Rows(r).Cells.Count 41s = tb.Rows(r).Cells(c).Shape.TextFrame2.TextRange.Text 42'宛先 43If InStr(s, "専用") Then 44f1 = True 45mailTo = "aquarius0319" 46End If 47If InStr(s, "フレッツ") Then 48f1 = True 49mailTo = "b230420" 50End If 51If InStr(s, "INS") Then 52f1 = True 53mailTo = "b230420" 54End If 55If f1 Then Exit Do 56Next 57Next 58End If 59Next 60Next 61MsgBox "無かった" 62Loop Until True 63pr.Close 64 65If Not (f1) Then Exit Sub 66' 67MsgBox "見つけた" 68 69 70Set ol = CreateObject("Outlook.Application") 71Set mail = ol.CreateItem(olMailItem) 72mail.Display 73 74mail.To = mailTo '宛先 75mail.Subject = "件名" 76mail.Body = "本文" 77 78'添付ファイル 79mail.Attachments.Add file 80 81'添付ファイル 82With Application.FileDialog(msoFileDialogOpen) 83.Filters.Clear 84.Filters.Add "添付ファイル", "*.*" 85.InitialFileName = "C:\" 86.AllowMultiSelect = True 87If .Show Then 88Dim o As Integer 89For o = 1 To .SelectedItems.Count 90mail.Attachments.Add .SelectedItems(o) 91Next 92End If 93End With 94 95'メール送信 96mail.Send '送信 97 98ol.Quit 99 100End Sub
以前にも書きましたが、デバッグ実行して処理が呼ばれているか確認してみて下さい。
VBAの場合、F8キーでステップ実行(1行ずつ実行)が行えます。