メールファイル(msgファイル)情報取得
コード
Sub msgファイル取得()
Dim OL As Outlook.Application
Dim msg As Object
Dim strFileName As String
strFileName = ファイル選択()
Set OL = New Outlook.Application
On Error Resume Next
Set msg = OL.CreateItemFromTemplate(strFileName)
If Err <> 0 Then
MsgBox Err.Description
Exit Sub
End If
On Error GoTo 0
With msg
MsgBox msg.SentOn & vbCrLf & msg.Subject
End With
End Sub
Function ファイル選択()
With Application.FileDialog(msoFileDialogFilePicker) 'FileDialogオブジェクト
.InitialFileName = ThisWorkbook.Path & "\"
.Show
ファイル選択 = .SelectedItems(1)
End With
End Function
解説
ツール>オプション>参照設定の「Microsoft Outlook 16.0 Object Library」のチェックをオンにしておくこと。