vbaでワードに反応してメールを送るvbaを作ったのですが自由に添付ファイルをつけれるようにしたいです
どうしたらいいでしょうか?
Sub ファイル自由参照()
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
With Application.FileDialog(msoFileDialogOpen)
.Filters.Add "ppt", "*.ppt?"
.InitialFileName = "ファイル名"
.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
MsgBox "無かった"
Loop Until True
pr.Close
If Not (f1 And f2) Then Exit Sub
MsgBox "見つけた" 'メール送信
Set ol = CreateObject("Outlook.Application")
Set mail = ol.CreateItem(olMailItem)
mail.Display
mail.To = "メアド" '宛先
mail.Subject = "件名"
mail.Body = "本文"
mail.Send '送信
ol.Quit
End Sub
No.1ベストアンサー
- 回答日時:
こんばんは、
>VBA 添付ファイルをつけてメールを送る方法について
>自由に添付ファイルをつけれるようにしたいです
自由の意味がわからないのですが
Attachments.Addメソッドで添付できると思います
MsgBox "見つけた" 'メール送信 より下の部分が該当します。
A1セルに添付ファイルのファイル拡張子を含むフルパスが記載されている場合
書き換えていますが、こんな感じ
Set ol = CreateObject("Outlook.Application")
With ol.CreateItem(olMailItem)
.To = "メアド" '宛先
.Subject = "件名"
.Body = "本文"
.Attachments.Add Cells(1, 1).Text, 1, 1, "Test"
.Display
'.Send '送信
End With
ol.Quit
1はOlAttachmentType olByValue 元のファイルのコピーを添付です
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
phpでメール送信できません 原...
-
PHPsendmailにて送信元を変更
-
PHPでメールを送信するには
-
PHPのif文でその処理を途中で抜...
-
「@$変数」の「@の意味は?」
-
PHPで新しいウインドウで開く命...
-
FTPコマンドでディレクトリごと...
-
VBSの「MsgBox」について
-
トランザクションが原因?DBに...
-
「クラウドにアップロード」」...
-
レジストリにあるアプリケーシ...
-
is_fileでファイルが存在してい...
-
xamppでformによるデータの送信...
-
glob関数で日本語文字が取得で...
-
Struts2 ファイルアップロード
-
フォントの色を変えるには?
-
onedrive にexcelファイルをア...
-
「クラス関数」「メンバ関数」...
-
php で C言語のdefineマクロの...
-
VB2008でFTPでのディ...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
ローカル環境でのメール送信
-
さくらサーバーにて、phpからメ...
-
コマンドプロンプト、VBSでの添...
-
mb_send_mail関数が利用出来ない
-
mb_send_mail() 第 4、5 引数の...
-
mail関数を使った場合のReturn-...
-
mailやmb_send_mail関数で、本...
-
サーバーによってはmb_send_mai...
-
VBA 添付ファイルをつけてメー...
-
PHPMailerのコードエラーが解決...
-
PHPでメールが送信できない
-
PHPでメールを送信するには
-
メール受信エラー【Net/POP3.php】
-
phpでメール送信できません 原...
-
PHPからメールを送る@さくらイ...
-
mb_send_mail の出力をファイル...
-
PHPsendmailにて送信元を変更
-
Parse errorの対処法について
-
こんにちは。PHPでメールフォー...
-
ワードプレス 予約システム
おすすめ情報