https://cybernews.com/personal-data-leak-check/
Affichage des articles dont le libellé est mail. Afficher tous les articles
Affichage des articles dont le libellé est mail. Afficher tous les articles
jeudi 18 février 2021
mercredi 25 mars 2015
Outlook VBA : mark a folder/subfolders tree as read
I have been forced to use Outlook (2010), and one of the main features I've been missing was to be able to mark all a folder and sub-folders trees as read in 1 shot. The solution I found was to activate the VBA macros, and to link one as a task icon in the usual Outlook views.
Note that the macro given below is prompting a list of your outlook folders. This could be enhanced by choosing the selected folder since outlook doesn't allow to select
Right click on the arrow at the right end of the Quick Access Toolbar (top right of the outlook window)
Select "More Commands"
On the left panel, select "Macros" (by default it's on "Popular Commands")
Select your Macro on the list, and hit "Add >>". If you have some other icons, you can reorganize them with the up & down arrow on the right.
Note that the macro given below is prompting a list of your outlook folders. This could be enhanced by choosing the selected folder since outlook doesn't allow to select
How to activate the Developer tab in outlook and authorize the Macro execution
- Go to the "File"
- Go to "Options" to open the "Outlook Options" window
- In "Customize Ribbon", on the right panel, select "Developer".
- Finish this step with "Ok".
- Go to "Trust Center", then "Trust Center Settings" to open the "Trust Center" window
- Go to "Macro Settings".
- Select "Enable all macros (not recommended; potentially dangerous code can run)".
- Finish by clicking "Ok" to close the "Trust Center" and the "Outlook option" windows.
How to create a VBA macro in Outlook
A macro is any public subroutine in a code module. A function or a private subroutine cannot be a macro, and a macro cannot be located in a class or form module. To create a new macro :(from ref [2])
- In Outlook, on the Developer tab of the Microsoft Office Fluent ribbon, click Visual Basic.
- In the Project window, double-click the module you want to contain the macro.
- On the Insert menu, click Procedure.
- In the Name box, type a name for the macro. The name cannot contain spaces.
- Click OK. The template for the macro subroutine appears in the code module window.
- Type the code you want to run in the body of the subroutine.
Source Code of the Macro
Sub MarkAllRead() Dim ResultFolder As Folder Dim Folder As Folder Dim item As MailItem Dim BaseFolder As Outlook.MAPIFolder Dim WalkResult As Long Set BaseFolder = Application.GetNamespace("MAPI").PickFolder Set ResultFolder = GetFolder(BaseFolder.FolderPath) For Each Folder In ResultFolder.Folders WalkResult = GetNextLevel(ResultFolder.FolderPath) For Each item In Folder.Items.Restrict("[unread] = true") item.UnRead = False Next Next Set ResultFolder = Nothing Set Folder = Nothing Set item = Nothing End Sub Function GetNextLevel(strFolderPath As String) As Long Dim WalkResultFolder As Folder Dim Folder As Folder Dim item As MailItem Dim WalkResult As Long Set WalkResultFolder = GetFolder(strFolderPath) For Each Folder In WalkResultFolder.Folders WalkResult = GetNextLevel(Folder.FolderPath) For Each item In Folder.Items.Restrict("[unread] = true") item.UnRead = False Next Next Set ResultFolder = Nothing Set Folder = Nothing Set item = Nothing End Function Function GetFolder(strFolderPath As String) As MAPIFolder Dim colFolders As Outlook.Folders Dim objFolder As Outlook.MAPIFolder Dim arrFolders() As String Dim i As Long On Error Resume Next strFolderPath = Replace(strFolderPath, "\\", "") strFolderPath = Replace(strFolderPath, "/", "\") arrFolders() = Split(strFolderPath, "\") Set objFolder = Application.GetNamespace("MAPI").Folders.item(arrFolders(0)) If Not objFolder Is Nothing Then For i = 1 To UBound(arrFolders) Set colFolders = objFolder.Folders Set objFolder = Nothing Set objFolder = colFolders.item(arrFolders(i)) If objFolder Is Nothing Then Exit For End If Next End If Set GetFolder = objFolder Set colFolders = Nothing End Function(from ref [1] )
How to add a quick access link to your macro
Sources / references
- [1]Source code of the macro, User=Stonywall, website(forum)=www.mrexcel.com
- [2]How to set up a VBA Macro in outlook2010
To Do
Change the macro so that it directly takes the selected Folder as an input.
Inscription à :
Articles (Atom)