Outlook 2019 Macro GoTo user defined search folder

Status
Not open for further replies.

Witzker

Senior Member
OS Version(s)
  1. iOS
Outlook version
Outlook 2019 32-bit
Email Account
Exchange Server 2007
Hi,

I want to speed up workflow in OL 2019 GERMAN version

I have this macro to goto inbox
Code:
Sub GoTo_Posteingang()
Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderInbox)
End Sub

How to modify this to GoTo the use defined seachfolder:
1678572951568.png

Hope for help

PS:
I tried with this macro to find the right name, but this does not work:
Code:
Sub ListSearchFolders()
    Dim myNamespace As NameSpace
    Dim mySearchFolders As Folders
    Dim myFolder As Folder
    Dim myItems As Items
    Dim myItem As Object
    Dim msgBody As String
   
    'Get the default Inbox folder and the search folders in it
    Set myNamespace = Application.GetNamespace("MAPI")
    Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
    Set mySearchFolders = myFolder.Folders
   
    'Loop through each search folder and add its name to the message body
    For Each myFolder In mySearchFolders
        If myFolder.DefaultItemType = olMailItem And myFolder.IsSearchFolder Then
            msgBody = msgBody & vbCrLf & myFolder.Name
        End If
    Next myFolder
   
    'Create a new email message with the search folder names in the body
    Set myItems = myNamespace.GetDefaultFolder(olFolderDrafts).Items
    Set myItem = myItems.Add(olMailItem)
    myItem.To = "recipient@example.com"
    myItem.Subject = "List of Search Folders"
    myItem.Body = "The following search folders are defined in your Inbox:" & vbCrLf & msgBody
    myItem.Display
   
    'Clean up
    Set myNamespace = Nothing
    Set mySearchFolders = Nothing
    Set myFolder = Nothing
    Set myItems = Nothing
    Set myItem = Nothing
End Sub

1678572884897.png
 
Are you just trying to make a list of search folders?

This might be a little more efficient:

You need to replace the debug print with the email stuff, but it should be faster.
 
Are you just trying to make a list of search folders?

This might be a little more efficient:

You need to replace the debug print with the email stuff, but it should be faster.
THX The output was:
\\email@gmail.com\Suchordner\Ungelesene Nachrichten

What now to put in this macro to go there?
Code:
Sub GoTo_Ungelesene_Nachrichten()

Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderInbox)

End Sub

I tried this but the folder stay the same as it was when I satartd the macro
Code:
Sub GoToSearchFolder()
    Dim myFolder As Folder
    Dim myNamespace As NameSpace
    Dim mySearchFolder As searchFolder
    
    Set myNamespace = Application.GetNamespace("MAPI")
    Set mySearchFolder = myNamespace.GetSearchFolders().Item("Ungelesene Nachrichten")
    
    If Not mySearchFolder Is Nothing Then
        Set myFolder = mySearchFolder.Folder
        Set Application.ActiveExplorer.CurrentFolder = myFolder
    Else
        MsgBox "Search folder not found."
    End If
End Sub

Pls help to get this correct
Many THX
 
Last edited:
So before or after the macro makes the search folder, you want to select the inbox? (The selected folder won't matter for search folders - they aren't in the inbox.)

If you want to switch to the inbox, use .Display

Session.GetDefaultFolder(olFolderInbox).display

or in your code:
myFolder.display
 
NO! NO!
You total misunderstood my demand!
Sorry !
So I try again to explain what the desired macro should do

following this macro which worx:
Code:
Sub GoTo_Ungelesene_Nachrichten()

Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderInbox)

End Sub
I just want a new macro that sets the focus not in the INBOX! Instead of the INBOX, the existing standard Search Folder ("Ungelesene Nachrichten")
Should be adressed

so instead of GOTO INBOX - GOTO Seachfolder ("Ungelesene Nachrichten")

That's ALL
I hope I have now cleared me demand

many THX for the hint HowTo
 
I found This, But
Code:
Sub EnumerateSearchFolderItems(ByVal sSearchFolderName As String)
    Dim oOutlook              As Object    'Outlook.Application
    Dim oNameSpace            As Object    'Outlook.Namespace
    Dim oStores               As Object    'Outlook.Stores
    Dim oStore                As Object    'Outlook.Store
    Dim oFolder               As Object    'Outlook.folder
    Dim i                     As Long

    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")        'Bind to existing instance of Outlook
    If Err.Number <> 0 Then        'Could not get instance, so create a new one
        Err.Clear
        Set oOutlook = CreateObject("Outlook.Application")
    End If
    On Error GoTo Error_Handler
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    Set oStores = oNameSpace.Session.Stores
    For Each oStore In oStores
        Set oFolder = oStore.GetSearchFolders.Item(sSearchFolderName)
        If Not oFolder Is Nothing Then
            With oFolder.items
                For i = 1 To .Count
                    Debug.Print i, .Item(i).SenderName, .Item(i).Subject, .Item(i).ReceivedTime, .Item(i).Categories
                Next i
            End With
            Exit For
        End If
    Next
Error_Handler_Exit:
    On Error Resume Next
    If Not oFolder Is Nothing Then Set oFolder = Nothing
    If Not oStore Is Nothing Then Set oStore = Nothing
    If Not oStores Is Nothing Then Set oStores = Nothing
    If Not oNameSpace Is Nothing Then Set oNameSpace = Nothing
    If Not oOutlook Is Nothing Then Set oOutlook = Nothing
    Exit Sub
 
Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: EnumerateSearchFolderItems" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Sub
I do not understand how to modify to just GOTO my Seachfolder ("Ungelesene Nachrichten")
 
Any news?
It sounds very simple jut to have a macro that goes to a search folder

But no solution?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 0
H Macro to Delete Duplicate items in Outlook calendar where title is the same and date is the same Outlook VBA and Custom Forms 0
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
mrrobski68 Issue with Find messages in a conversation macro Outlook VBA and Custom Forms 1
G Creating Macro to scrape emails from calendar invite body Outlook VBA and Custom Forms 6
M Use Macro to change account settings Outlook VBA and Custom Forms 0
J Macro to Reply to Emails w/ Template Outlook VBA and Custom Forms 3
C Outlook - Macro to block senders domain - Macro Fix Outlook VBA and Custom Forms 1
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 0
S macro error 4605 Outlook VBA and Custom Forms 0
A Macro Mail Alert Using Outlook 4
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
D Outlook 2016 Creating an outlook Macro to select and approve Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
M Outlook 2019 Macro not working Outlook VBA and Custom Forms 0
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
D Auto Remove [EXTERNAL] from subject - Issue with Macro Using Outlook 21
V Macro to count flagged messages? Using Outlook 2
sophievldn Looking for a macro that moves completed items from subfolders to other subfolder Outlook VBA and Custom Forms 7
S Outlook Macro for [Date][Subject] Using Outlook 1
E Outlook - Macro - send list of Tasks which are not finished Outlook VBA and Custom Forms 3
E Macro to block senders domain Outlook VBA and Custom Forms 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
N VBA Macro To Save Emails Outlook VBA and Custom Forms 1
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
J Macro to Insert a Calendar Outlook VBA and Custom Forms 8
W Macro to Filter Based on Latest Email Outlook VBA and Custom Forms 6
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
D Autosort macro for items in a view Outlook VBA and Custom Forms 2
S HTML to Plain Text Macro - Help Outlook VBA and Custom Forms 1
A Macro to file emails into subfolder based on subject line Outlook VBA and Custom Forms 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
S Visual indicator of a certain property or to show a macro toggle Outlook VBA and Custom Forms 2
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
S Macro to extract and modify links from emails Outlook VBA and Custom Forms 3
M Replyall macro with template and auto insert receptens Outlook VBA and Custom Forms 1
L Macro to add Date & Time etc to "drag to save" e-mails Outlook VBA and Custom Forms 17
S Macro for Loop through outlook unread emails Outlook VBA and Custom Forms 2
Globalforester ItemAdd Macro - multiple emails Outlook VBA and Custom Forms 3
S Macro to extract email addresses of recipients in current drafted email and put into clipboard Outlook VBA and Custom Forms 2
Witzker HowTo start a macro with an Button in OL contact form Outlook VBA and Custom Forms 12
Witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 7
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 23

Similar threads

Back
Top