1
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.Folderオブジェクトの取得方法まとめ(VBA)

Posted at

概要

Outlookでメールフォルダを操作する際に必須となる、Outlook.Folder オブジェクトの取得方法を2種類紹介します。

前提

  • 「ツール(T)」 → 「参照設定(R)」から「Microsoft Outlook 16.0 Object Library」にチェックを入れてください。

1. 既定のフォルダを取得する(GetDefaultFolder)

受信トレイや送信済みアイテムなどの既定フォルダは、GetDefaultFolder メソッドで取得できます。

公式リファレンス:Namespace.GetDefaultFolder method (Outlook)

例:受信トレイを取得

Dim f As Outlook.Folder
Set f = Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox)
  • 引数には OlDefaultFolders に定義されているフォルダ種別を指定します。
  • 取得可能なフォルダ種別一覧はこちら

2. 任意のフォルダを取得する(Foldersプロパティ)

既定フォルダ以外のフォルダは、Folders プロパティを使って階層的に指定します。

例:特定アカウント配下の「TARGET」フォルダを取得

Dim f As Outlook.Folder
Set f = Outlook.Application.GetNamespace("MAPI").Folders("neko.the.shadow@example.com").Folders("TARGET")

フォルダは階層構造になっているため、必要に応じて Folders をチェーンしてアクセスします。

動作環境

  • Microsoft Visual Basic for Applications 7.1
1
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
1
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?