メインコンテンツへスキップ

Outlookの起動時にすべてのフォルダを自動的に展開するにはどうすればよいですか?

通常、Outlook のナビゲーション ウィンドウでフォルダーを展開または折りたたんでプログラムを閉じると、Outlook を再度開いてもフォルダーは展開または折りたたまれた状態を保持します。 ただし、Outlook を起動するたびにすべてのフォルダーが自動的に展開されるようにしたい場合はどうすればよいでしょうか。 この記事では、まさにそれを実現するための VBA ソリューションを提供します。

VBA を使用して Outlook を起動するときにすべてのフォルダーを自動的に展開する

Office タブ - Microsoft Office でタブによる編集と参照を有効にし、仕事をスムーズにします
Kutools for Outlook - 100 以上の高度な機能で Outlook を強化し、優れた効率を実現します
これらの高度な機能を使用して、Outlook 2021 ~ 2010 または Outlook 365 を強化します。 包括的な 60 日間の無料トライアルを利用して、メール エクスペリエンスを向上させてください。

矢印青い右バブル VBA を使用して Outlook を起動するときにすべてのフォルダーを自動的に展開する

このガイドでは、VBA スクリプトを使用して、Outlook を起動するたびにナビゲーション ウィンドウ内のすべてのフォルダーを自動的に展開する方法を説明します。 VBA スクリプトを実装するには、次の手順に従います。

  1. イベント Altキー+ F11 キーを同時に開いて アプリケーション向け Microsoft Visual Basic 窓。
  2. 拡大する プロジェクト1 & MicrosoftOutlookオブジェクト セクションに プロジェクト ペインをダブルクリックして開きます このOutlookSession ウィンドウを開き、以下の VBA コードをそこに貼り付けます。

    VBA:Outlookのすべてのフォルダーを自動的に展開します

    Public WithEvents GEx As Explorer
    Public GFlag As Boolean
    Private Sub Application_Startup()
      'Update by ExtendOffice 2023/12/08
      Set GEx = Application.ActiveExplorer
      GFlag = False
    End Sub
    
    Private Sub GEx_SelectionChange()
      If GFlag = False Then
        ExpandAllFolders
      End If
      GFlag = True
    End Sub
    
    Public Sub ExpandAllFolders()
      Dim xNameSpace As Outlook.NameSpace
      Dim xFlds As Outlook.Folders
      Dim xCurrFld As Outlook.MAPIFolder
      Dim xFld As Outlook.MAPIFolder
      Dim xExpandDefaultStoreOnly As Boolean
      Dim xModule As NavigationModule
      On Error Resume Next
      xExpandDefaultStoreOnly = False
      Set xNameSpace = Application.Session
      Set xModule = Application.ActiveExplorer.NavigationPane.CurrentModule
      Set xCurrFld = Application.ActiveExplorer.CurrentFolder
      If xExpandDefaultStoreOnly = True Then
        Set xFld = xNameSpace.GetDefaultFolder(olFolderInbox)
        Set xFld = xFld.Parent
        Set xFlds = xFld.Folders
        LoopFolders xFlds, True
      Else
        LoopFolders xNameSpace.Folders, True
        LoopFolders xNameSpace.Folders, False
      End If
      DoEvents
      Set Application.ActiveExplorer.NavigationPane.CurrentModule = xModule
      Set Application.ActiveExplorer.CurrentFolder = xCurrFld
      Set xNameSpace = Nothing
      Set xModule = Nothing
      Set xCurrFld = Nothing
    End Sub
    
    Private Sub LoopFolders(Flds As Outlook.Folders, ByVal All As Boolean)
      Dim xFld As Outlook.MAPIFolder
      On Error Resume Next
      For Each xFld In Flds
        Select Case All
          Case True
            If xFld.DefaultItemType = olMailItem Then
              Set Application.ActiveExplorer.CurrentFolder = xFld
              DoEvents
              If xFld.Folders.Count > 0 Then
                LoopFolders xFld.Folders, All
              End If
            End If
          Case False
            Set Application.ActiveExplorer.CurrentFolder = xFld
            DoEvents
            If xFld.Folders.Count > 0 Then
              LoopFolders xFld.Folders, All
            End If
        End Select
      Next
    End Sub
  3. コードを保存して閉じます アプリケーション向け Microsoft Visual Basic 窓。

今後、Outlookを再起動すると、すべてのフォルダがOutlookで自動的に展開されます。

注意:

  • この VBA は、Outlook の再起動時に折りたたまれた検索フォルダーを開くことができません。
  • VBA スクリプトが正しく機能することを確認するには、Outlook でマクロ設定を調整することが重要です。 に行ってください File > オプション > トラストセンター (英語のみ) > セキュリティセンターの設定 > マクロ設定を選択し、 すべてのマクロを有効にする オプション。 この設定により、VBA スクリプトを制限なく実行できるようになります。

矢印青い右バブル 関連記事


最高のオフィス生産性向上ツール

Kutools for Outlook - Outlook を強化する 100 以上の強力な機能

🤖 AIメールアシスタント: AI の魔法を備えたインスタント プロのメール - ワンクリックで天才的な返信、完璧な口調、多言語の習得。メールを簡単に変革しましょう! ...

📧 自動メール: 不在時 (POP および IMAP で利用可能)  /  メール送信のスケジュール設定  /  メール送信時のルールによる自動CC/BCC  /  自動転送 (高度なルール)   /  あいさつを自動追加   /  複数受信者の電子メールを個別のメッセージに自動的に分割する ...

📨 電子メール管理: メールを簡単に思い出す  /  件名などで詐欺メールをブロック  /  重複するメールを削除する  /  高度な検索  /  フォルダーを統合する ...

📁 アタッチメント プロバッチ保存  /  バッチデタッチ  /  バッチ圧縮  /  自動保存   /  自動デタッチ  /  自動圧縮 ...

🌟 インターフェースマジック: 😊もっと可愛くてクールな絵文字   /  タブ付きビューで Outlook の生産性を向上  /  Outlook を閉じる代わりに最小化する ...

???? ワンクリックの驚異: 受信した添付ファイルをすべてに返信する  /   フィッシングメール対策  /  🕘送信者のタイムゾーンを表示 ...

👩🏼‍🤝‍👩🏻 連絡先とカレンダー: 選択したメールから連絡先を一括追加  /  連絡先グループを個別のグループに分割する  /  誕生日のリマインダーを削除する ...

オーバー 100の特長 あなたの探索をお待ちしています! ここをクリックして詳細をご覧ください。

 

 

Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Just tried this on Microsoft® Outlook® for Microsoft 365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit and it was unsuccessful
This comment was minimized by the moderator on the site
Hi there,

Please go to File > Options > Trust Center > Trust Center Settings > Macro Settings. And select the Enable all macros option. After making this change, restart Outlook, the macro should then be operational.
This comment was minimized by the moderator on the site
Hi guys,

does this code also work for Microsoft outlook 365?
I have tried and tried again, but I get no results.
Thanks.
This comment was minimized by the moderator on the site
I couldn't get this macro to work either.
This comment was minimized by the moderator on the site
Hi there,
We've updated the code, please try it again. 🙂
Amanda
This comment was minimized by the moderator on the site
I cannot get this macro to work at all.  All folders in the Folder pane are not expanded at all.  I am using Outlook 2021.  Is there some instruction I missed?
This comment was minimized by the moderator on the site
Hi there,
We've updated the code, please try it again. 🙂
Amanda
This comment was minimized by the moderator on the site
Thank you so much.. It solved my problem. :)
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations