Vai al contenuto principale

Come espandere automaticamente tutte le cartelle all'avvio di Outlook?

In genere, quando si espande o si comprime una cartella nel riquadro di spostamento di Outlook e successivamente si chiude il programma, la cartella mantiene lo stato espanso o compresso alla riapertura di Outlook. Tuttavia, cosa succede se desideri che tutte le cartelle vengano espanse automaticamente ogni volta che avvii Outlook? Questo articolo fornisce una soluzione VBA per raggiungere proprio questo obiettivo.

Espandi automaticamente tutte le cartelle all'avvio di Outlook utilizzando VBA

Scheda Office: abilita la modifica e la navigazione a schede in Microsoft Office, rendendo il lavoro un gioco da ragazzi
Kutools per Outlook: potenzia Outlook con oltre 100 funzionalità avanzate per un'efficienza superiore
Potenzia il tuo Outlook 2021-2010 o Outlook 365 con queste funzionalità avanzate. Goditi una prova gratuita completa di 60 giorni e migliora la tua esperienza di posta elettronica!

freccia blu freccia destra Espandi automaticamente tutte le cartelle all'avvio di Outlook utilizzando VBA

Questa guida mostrerà come utilizzare uno script VBA per espandere automaticamente tutte le cartelle nel riquadro di spostamento ogni volta che si avvia Outlook. Seguire questi passaggi per implementare lo script VBA:

  1. Rassegna Stampa Alt + F11 tasti contemporaneamente per aprire il file Microsoft Visual Basic, Applications Edition finestra.
  2. espandere la Progetto 1 ed Oggetti di Microsoft Outlook nel Progetto riquadro, fare doppio clic per aprire il file Questa sessione di Outlook finestra, quindi incollare al suo interno il codice VBA seguente.

    VBA: espandi automaticamente tutte le cartelle in 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. Salva il codice e chiudi il file Microsoft Visual Basic, Applications Edition finestra.

D'ora in poi, al riavvio di Outlook, tutte le cartelle verranno automaticamente espanse in Outlook.

Note:

  • Questo VBA non può aprire le cartelle di ricerca compresse al riavvio di Outlook.
  • Per garantire che lo script VBA funzioni correttamente, è essenziale modificare le impostazioni macro in Outlook. Per favore vai a Compila il > Opzioni > Centro protezione > Impostazioni del centro di fiducia > Impostazioni macroe selezionare il Abilita tutte le macro opzione. Questa impostazione consente l'esecuzione dello script VBA senza alcuna restrizione.

freccia blu freccia destra Articoli Correlati


I migliori strumenti per la produttività in ufficio

Kutools for Outlook - Oltre 100 potenti funzionalità per potenziare il tuo Outlook

🤖 Assistente di posta AI: E-mail istantanee professionali con la magia dell'intelligenza artificiale: risposte geniali con un solo clic, tono perfetto, padronanza multilingue. Trasforma l'e-mail senza sforzo! ...

???? Automazione di posta elettronica: Fuori sede (disponibile per POP e IMAP)  /  Pianifica l'invio di e-mail  /  CC/BCC automatico in base alle regole durante l'invio di e-mail  /  Inoltro automatico (regole avanzate)   /  Aggiunta automatica di saluto   /  Suddividi automaticamente le email con più destinatari in singoli messaggi ...

📨 gestione e-mail: Richiama facilmente le email  /  Blocca le email truffe per soggetto e altri  /  Elimina email duplicate  /  Ricerca avanzata  /  Consolidare cartelle ...

📁 Allegati ProSalvataggio in batch  /  Stacca batch  /  Comprimi in lotti  /  Salvataggio automatico   /  Scollegamento automatico  /  Comprimi automaticamente ...

🌟 Magia dell'interfaccia: 😊Più emoji carini e fantastici   /  Aumenta la tua produttività in Outlook con le visualizzazioni a schede  /  Riduci a icona Outlook invece di chiuderlo ...

👍 Meraviglie con un clic: Rispondi a tutti con gli allegati in arrivo  /   E-mail anti-phishing  /  🕘Mostra il fuso orario del mittente ...

👩🏼‍🤝‍👩🏻 Contatti e calendario: Aggiungi in batch contatti dalle email selezionate  /  Dividere un gruppo di contatti in singoli gruppi  /  Rimuovi promemoria compleanno ...

Al di sopra Caratteristiche 100 Attendi la tua esplorazione! Clicca qui per scoprire di più.

 

 

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