A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

ThisOutlookSession - code runs only once



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old July 13th 06, 04:08 AM posted to microsoft.public.outlook.program_vba
Rafael1119
external usenet poster
 
Posts: 5
Default ThisOutlookSession - code runs only once

All, I'm trying to use the code below as explained on this page:
http://msdn.microsoft.com/library/de...11olevents.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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 "find" contacts doesn't work, just runs and runs Tom Stanley Outlook - Using Contacts 1 July 5th 06 03:56 AM
ThisOutlookSession not starting Wanda Outlook and VBA 2 June 9th 06 07:48 PM
Vba Project OTM - Thisoutlooksession(code) error XP User Outlook and VBA 4 May 7th 06 03:31 PM
Code runs in design mode karlman Outlook - Using Forms 2 January 27th 06 05:49 PM
My program runs very slow קובץ Outlook and VBA 6 January 22nd 06 03:46 PM


All times are GMT +1. The time now is 07:55 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.