「Alt」キーを押しながら「F11」キーを押して、Microsoft Visual Basic for Applications(VBA)ウィンドウを開きます。
「挿入」メニューから「モジュール」を選択し、新しいモジュールを追加します。
以下のVBAコードをコピーして、モジュールに貼り付けます。
Public Sub SaveAttachmentsWithoutOpening()
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xAttachment As Outlook.Attachment
Dim i As Long
Dim xCount As Long
Dim xFileName As String
Dim xSavePath As String
Dim xOriginalFiles As String
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseForFolder(0, "Select a folder:", 0, strStartingFolder)
Dim GCount As Integer
Dim GFilepath As String
Public Sub SaveAttachments()
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xSelection As Outlook.Selection
Dim i As Long
Dim xAttCount As Long
Dim xFilePath As String, xFolderPath As String, xSaveFiles As String
On Error Resume Next
xFolderPath = CreateObject("WScript.Shell").SpecialFolders(16)
Set xSelection = Outlook.Application.ActiveExplorer.Selection
xFolderPath = xFolderPath & "\Attachments\"
If VBA.Dir(xFolderPath, vbDirectory) = vbNullString Then
VBA.MkDir xFolderPath
End If
GFilepath = ""
For Each xMailItem In xSelection
Set xAttachments = xMailItem.Attachments
xAttCount = xAttachments.Count
xSaveFiles = ""
If xAttCount > 0 Then
For i = xAttCount To 1 Step -1
GCount = 0
xFilePath = xFolderPath & xAttachments.Item(i).FileName
コメント