0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自分用メモ:Outlook VBAでメッセージ(.msg)ファイル保存するマクロ

Posted at

いちいち所定のフォルダを開いてメールをコピペするのも面倒だったので作りました。
本当はBoxまで繋げたかったけど、パワーオートメイト組むのもめんどくさいのでいつか…。

「参考にしたサイト」に内包されているので本記事は読まなくていいと思います。

Outlook VBAでメッセージ(.msg)ファイル保存するマクロを組む

以下、参考にしたサイト
001 Outlook VBA メール本体と添付資料を一発保存マクロ シンプル版 - くのへスタジオ (kunohe.tech)

ThisOutlookSession.vba

Sub メール保存() '参考ページ→ https://kunohe.tech/outlook-vba/300/

  Dim objIns As Outlook.Inspector
  Dim objItem As Object
  'Dim strName As String
  Dim subjectName As String
  Dim strPath As String
  Dim objAttachment As Object
  'Dim objFSO As Object
  Dim strFile As String
 
  Set objIns = Application.ActiveInspector
  Set objItem = objIns.CurrentItem
  
  strPath = "C:\Users\お好きなパス\" 'ファイルを保存したい場所のアドレス。末尾に「\」を付けること
  subjectName = objItem.Subject
  
  If subjectName Like "*:*" Then 'メール件名に「:」があれば「_」に置換
    subjectName = Replace(subjectName, ":", "_")
  End If
  
  objItem.SaveAs strPath & subjectName & ".msg"

  With objItem
    For Each objAttachment In .Attachments
        strFile = strPath & strName & "\" & objAttachment
        objAttachment.SaveAsFile strFile
    Next objAttachment
  End With

End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?