先日に引き続きお願いいたします。
前回、フォルダ内のファイルをすべて添付する方法を教えていただき
うまくできました。
今回本文に、あいさつ文と添付したファイル名をすべて追加したいので
以下の赤字部分を追加してみました。がうまくできません。
どのように変更すればよいのかご指導お願いいたします。
よろしくお願いいたします。
複数参考サイトからコードをいただいてます。
見難くなっていると思います。申し訳ありません。
Dim Fs, strPath, Fl, F, NewFile, NewFileFP, OutF
Dim objFileSys
Dim objFolder
Dim objFile
Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("Wscript.Shell")
Set oMsg = CreateObject("CDO.Message")
'ファイルシステムを扱うオブジェクトを作成
Set objFileSys = CreateObject("Scripting.FileSystemObject")
'c:\temp フォルダのオブジェクトを取得
Set objFolder = objFileSys.GetFolder("z:\test")
Set Fs = CreateObject("Scripting.FileSystemObject")
strPath = "z:\test"
oMsg.From = "送信者 <sousin@xxxx.com>"
oMsg.To = "受信1 様 <jyusin1@xxxx.com>"
oMsg.Cc = "受信2 様 <jyusin2@xxxx.com>"
oMsg.Bcc = ""
oMsg.Subject = "テスト送信"
oMsg.TextBody = "担当者様" & vbCrLf & vbCrLf & "確認お願いします。" & vbCrLf & vbCrLf
'FolderオブジェクトのFilesプロパティからFileオブジェクトを取得
For Each objFile In objFolder.Files
'取得したファイルのファイル名を表示
'WScript.Echo objFile.Name
oMsg.TextBody.WriteLine objFile.Name
Next
If Fs.FolderExists(strPath) Then
Set Fl = Fs.GetFolder(strPath)
For Each F In Fl.Files
oMsg.AddAttachment F.Path
Next
Set Fl = Nothing
Else
MsgBox "フォルダー """ & strPath & """ を参照出来ません。", vbCritical, "エラー"
End If
Set objFolder = Nothing
Set objFileSys = Nothing
oMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.xxxx.com"
oMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
oMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
oMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxx%xxxx.com"
oMsg.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
oMsg.Configuration.Fields.Update
oMsg.Send
Set OutF = Fs.OpenTextFile("C:\FileSend\Fsend.log",8)
OutF.WriteLine "Date[" & date & "] Time[" & time & "] File[" & NewFile & "]"
OutF.Close
objShell.Popup "メール送信しました。", 0, "送信完了", 0
Set Fs = Nothing
Set Fl = Nothing
Set OutF = Nothing