をファイルに電子メールを送信して保存します。編集、我々は現在で満たされたすべてのテンプレートのテキストと件名、受信者、メッセージ本体と、自動的にVBAを使用してExcelで作成された電子メールを持っているシステム
Sub CreateMail(Optional sFile As String = "")
'Create email to send to requestor with attachment sFile
'Declarations
Dim app As Outlook.Application
Dim msg As Outlook.MailItem
Dim send_to As Recipient
Dim send_tos As Recipients
'Initiations
Set app = CreateObject("Outlook.Application")
Set msg = app.CreateItem(olMailItem)
Set send_tos = msg.Recipients
Set send_to = send_tos.Add("[email protected]")
send_to.Type = 1
'Create message
With msg
.SentOnBehalfOfName = "[email protected]"
.Subject = "This is the email subject"
.HTMLBody = "This is the email body" & vbCrLf
'Resolve each Recipient's name.
For Each send_to In msg.Recipients
send_to.Resolve
Next
If Len(sFile) > 0 Then
.Attachments.Add sFile
End If
.Display
End With
End sub
をいくつかの手動変更を行った後、作成された電子メールに送信して、ファイルシステム上のフォルダに自動的に(Outlookの通常の送信フォルダに加えて)コピーを保存します。 Excel VBA内でこれをすべて実行する方法はありますか?
Outlook VBAを使用している可能性がありますが、フォルダはExcelで定義されているため、1つのファイルにコードをまとめておきたいと思います。
[Windowsフォルダ内の選択した電子メールを保存するマクロ]の可能な複製(http://stackoverflow.com/questions/28479157/macro-to-save-selected-emails-of -outlook-in-windows-folder) –
特にExcel VBAを使用して保存したいと思っています。 – Vlad
Microsoft Outlookオブジェクトモデルへの参照を追加すると、他の回答で参照されているメソッドをExcel VBAで使用できます。もしあなたがどこを見るのか分からないなら、これは答えとしては良いでしょうか? –