R
Rafael1119
All, I'm trying to use the code below as explained on this page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnolbk02/html/odc_ch11olevents.asp
However, the code runs and it works fine when Outlook first runs but it does
not changes my view when I switch folders.
Any thoughts?
'ThisOutlookSession code
Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_objExplorer_FolderSwitch
End Sub
Listing 11.7 Enforcing a Default Folder View
'ExplEvents class module
Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer
Sub Class_Terminate()
Call DeRefExplorers
End Sub
Public Sub InitExplorers(objApp As Outlook.Application)
Set m_colExplorers = objApp.Explorers
If m_colExplorers.Count > 0 Then
Set m_objExplorer = objApp.ActiveExplorer
End If
End Sub
Public Sub DeRefExplorers()
Set m_colExplorers = Nothing
Set m_objExplorer = Nothing
End Sub
Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
m_explevents.m_objExplorer_FolderSwitch
End Sub
Public Sub m_objExplorer_FolderSwitch()
Set myOlApp = CreateObject("Outlook.Application")
Dim olns As Outlook.NameSpace
Set olns = myOlApp.GetNamespace("MAPI")
Dim SearchFolder As Outlook.MAPIFolder
Dim myOlExp As Outlook.Explorer
Dim vw As Outlook.View
Set myOlExp = myOlApp.ActiveExplorer
Set SearchFolder = myOlExp.CurrentFolder
myType = SearchFolder.DefaultItemType
Set vw = SearchFolder.CurrentView
If myType = 0 Then
MsgBox myType
'Set current view to "By Company"
If Not vw.Name = "MyView" Then
myOlExp.CurrentView = "MyView"
End If
End If
Set myOlApp = Nothing
Set olns = Nothing
Set SearchFolder = Nothing
Set myOlExp = Nothing
Set vw = Nothing
Set myType = Nothing
End Sub
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnolbk02/html/odc_ch11olevents.asp
However, the code runs and it works fine when Outlook first runs but it does
not changes my view when I switch folders.
Any thoughts?
'ThisOutlookSession code
Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_objExplorer_FolderSwitch
End Sub
Listing 11.7 Enforcing a Default Folder View
'ExplEvents class module
Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer
Sub Class_Terminate()
Call DeRefExplorers
End Sub
Public Sub InitExplorers(objApp As Outlook.Application)
Set m_colExplorers = objApp.Explorers
If m_colExplorers.Count > 0 Then
Set m_objExplorer = objApp.ActiveExplorer
End If
End Sub
Public Sub DeRefExplorers()
Set m_colExplorers = Nothing
Set m_objExplorer = Nothing
End Sub
Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
m_explevents.m_objExplorer_FolderSwitch
End Sub
Public Sub m_objExplorer_FolderSwitch()
Set myOlApp = CreateObject("Outlook.Application")
Dim olns As Outlook.NameSpace
Set olns = myOlApp.GetNamespace("MAPI")
Dim SearchFolder As Outlook.MAPIFolder
Dim myOlExp As Outlook.Explorer
Dim vw As Outlook.View
Set myOlExp = myOlApp.ActiveExplorer
Set SearchFolder = myOlExp.CurrentFolder
myType = SearchFolder.DefaultItemType
Set vw = SearchFolder.CurrentView
If myType = 0 Then
MsgBox myType
'Set current view to "By Company"
If Not vw.Name = "MyView" Then
myOlExp.CurrentView = "MyView"
End If
End If
Set myOlApp = Nothing
Set olns = Nothing
Set SearchFolder = Nothing
Set myOlExp = Nothing
Set vw = Nothing
Set myType = Nothing
End Sub