Running Solution Module in a class module called by Outlook or other VBA routines
This is a continuation of my trial of setting up a solution Module to run my EzGTD macros so that I can use Outlook 2010 as my GTD inbox
If thisoutlooksession looks crowded, you can move some of the codes into a class module. Then call the class module functions from thisoutlooksession_startup if you need it to automatically start with Outlook or from other VBA routines if you want to have on-demand functions.
In this example, i am going to put the routine to create a solution module that shows up in the navigation pane of outlook.
Put these codes into thisoutlooksession
Option Explicit
Dim m_SearchModule As New AddSolutionModule
Private Sub Application_Startup()
‘Create a Solution Module for EzGTD
‘The EzGTD Folder Name, you can change it
Const strFolderName As String = "EzGTD"
Call m_SearchModule.CreateSolutionModule(strFolderName)
End Sub
Put these code into a class module with name AddSolutionModule
Option Explicit
‘This routine would create a new folder EzGTD if it does not already exist
‘Then it would try to start the Solution Module so that it will show up in
‘The outlook Navigation Panel
‘Programmed by Ryan Lim ideasmiths@gmail.com
‘version 1.0 dated 3 may 2011
Public Sub CreateSolutionModule(ByVal strFolderName)
Dim objFolder As Outlook.Folder
‘Try to find the folder needed by Solution Module
Set objFolder = objSMFolder(strFolderName)
‘Turn on the Solution Module
Dim objSolModule As SolutionsModule
Set objSolModule = Application.ActiveExplorer.NavigationPane.Modules.GetNavigationModule(olModuleSolutions)
With objSolModule
.AddSolution objFolder, olShowInDefaultModules
.Visible = True
End With
‘Clean up
Set objFolder = Nothing
Set objSolModule = Nothing
End Sub
Private Function objSMFolder(ByVal strFolderName As String) As Outlook.Folder
‘Try to add a folder to the root folder, if it already exist an error will occur
On Error GoTo ErrorGenie
Set objSMFolder = Application.Session.GetDefaultFolder(olFolderInbox).Parent.Folders.Add(strFolderName)
Exit Function
ErrorGenie:
‘The folder EzGTD may already have been created, in this case just select it
Set objSMFolder = Application.Session.GetDefaultFolder(olFolderInbox).Parent.Folders.item(strFolderName)
End Function