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
  #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

Ads
  #2  
Old July 13th 06, 05:37 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default ThisOutlookSession - code runs only once

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move the code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")

by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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

  #3  
Old July 14th 06, 12:40 AM posted to microsoft.public.outlook.program_vba
Rafael1119
external usenet poster
 
Posts: 5
Default ThisOutlookSession - code runs only once


"Michael Bauer" wrote in message
...
What do you mean by "move the code from the second Application_Starup to the
first one"? I know it must be simple but I don't see what you mean.

Rafael

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move the
code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")

by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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


  #4  
Old July 14th 06, 06:01 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default ThisOutlookSession - code runs only once

Am Thu, 13 Jul 2006 19:40:09 -0400 schrieb Rafael1119:

Please look at your code: There´re two Application_Startup procedures. Only
the first one, in ThisOutlookSession, will be called by Outlook.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
What do you mean by "move the code from the second Application_Starup to

the
first one"? I know it must be simple but I don't see what you mean.

Rafael

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move the
code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")

by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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

  #5  
Old July 15th 06, 12:41 AM posted to microsoft.public.outlook.program_vba
Rafael1119
external usenet poster
 
Posts: 5
Default ThisOutlookSession - code runs only once


"Michael Bauer" wrote in message
...
Well, here what my code looks like now in the "ThisOutlookSession" but still
no joy. It fires during OL startup only.

Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
m_explevents.m_objExplorer_FolderSwitch
End Sub


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 m_colExplorers_NewExplorer _
(ByVal Explorer As Explorer)
Set m_objExplorer = Explorer
End Sub

Public Sub m_objExplorer_FolderSwitch()
Set myOlApp = 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
MsgBox myType
If myType = 0 Then
'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




Am Thu, 13 Jul 2006 19:40:09 -0400 schrieb Rafael1119:

Please look at your code: There´re two Application_Startup procedures.
Only
the first one, in ThisOutlookSession, will be called by Outlook.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
What do you mean by "move the code from the second Application_Starup to

the
first one"? I know it must be simple but I don't see what you mean.

Rafael

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move the
code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")
by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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


  #6  
Old July 15th 06, 08:35 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default ThisOutlookSession - code runs only once

Am Fri, 14 Jul 2006 19:41:12 -0400 schrieb Rafael1119:

From what I can see, only Application_Startup should be in
ThisOutlookSession, the rest in the ExplEvents class.

If that´s the case, please set a breakpoint (F9) on the

Public Sub m_objExplorer_FolderSwitch()

line (which is Private by default, not Public) and see is the execution
stops there. As long as you do not switch explorers, but folders, it should
do so.

For being able to switch also between explorers you need to have a class
module for each explorer.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
Well, here what my code looks like now in the "ThisOutlookSession" but

still
no joy. It fires during OL startup only.

Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
m_explevents.m_objExplorer_FolderSwitch
End Sub


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 m_colExplorers_NewExplorer _
(ByVal Explorer As Explorer)
Set m_objExplorer = Explorer
End Sub

Public Sub m_objExplorer_FolderSwitch()
Set myOlApp = 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
MsgBox myType
If myType = 0 Then
'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




Am Thu, 13 Jul 2006 19:40:09 -0400 schrieb Rafael1119:

Please look at your code: There´re two Application_Startup procedures.
Only
the first one, in ThisOutlookSession, will be called by Outlook.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
What do you mean by "move the code from the second Application_Starup to

the
first one"? I know it must be simple but I don't see what you mean.

Rafael

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move the
code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")
by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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

  #7  
Old July 15th 06, 03:03 PM posted to microsoft.public.outlook.program_vba
Rafael1119
external usenet poster
 
Posts: 5
Default ThisOutlookSession - code runs only once


"Michael Bauer" wrote in message
. ..
Michael,

I moved all my code out of ThisOutlookSession except for the event handler
below:

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
'm_explevents.m_objExplorer_FolderSwitch
End Sub

I removed the folder Switch event handler because as you mentioned, it's
typically private on the explevents class moduel which I changed back to
"Private".

The problem I have when setup this way is that this event does not fire at
all.

I'm going to try this with VSTO so will ping the VSTO newsgroup unless
you/others have some more detail instructions (if you have it working on
your end) on how to do this.

Thanks much for your efforts.

Rafael

Am Fri, 14 Jul 2006 19:41:12 -0400 schrieb Rafael1119:

From what I can see, only Application_Startup should be in
ThisOutlookSession, the rest in the ExplEvents class.

If that´s the case, please set a breakpoint (F9) on the

Public Sub m_objExplorer_FolderSwitch()

line (which is Private by default, not Public) and see is the execution
stops there. As long as you do not switch explorers, but folders, it
should
do so.

For being able to switch also between explorers you need to have a class
module for each explorer.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
Well, here what my code looks like now in the "ThisOutlookSession" but

still
no joy. It fires during OL startup only.

Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
m_explevents.m_objExplorer_FolderSwitch
End Sub


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 m_colExplorers_NewExplorer _
(ByVal Explorer As Explorer)
Set m_objExplorer = Explorer
End Sub

Public Sub m_objExplorer_FolderSwitch()
Set myOlApp = 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
MsgBox myType
If myType = 0 Then
'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




Am Thu, 13 Jul 2006 19:40:09 -0400 schrieb Rafael1119:

Please look at your code: There´re two Application_Startup procedures.
Only
the first one, in ThisOutlookSession, will be called by Outlook.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
What do you mean by "move the code from the second Application_Starup
to
the
first one"? I know it must be simple but I don't see what you mean.

Rafael

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move the
code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")
by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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


  #8  
Old July 17th 06, 05:48 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default ThisOutlookSession - code runs only once

Am Sat, 15 Jul 2006 10:03:43 -0400 schrieb Rafael1119:

I didn´t ask you to remove the FolderSwitch event procedure. So this is what
you need to have at least and where it should be located:

Now I see another error: Because you declare m_explevents within
Application_Startup it terminates as soon as the execution leaves that
procedure. Due to that you don´t have any event handlers.

Instead declare that variable also on the module level as shown:

ThisOutlookSession
Private m_explevents As ExplEvents

Private Sub Application_Startup()
Set m_explevents = New ExplEvents
End Sub
/ThisOutlookSession

ExplEvents
Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer

Public Sub InitExplorers(objApp As Outlook.Application)
End Sub

Public Sub DeRefExplorers()
End Sub

Private Sub m_colExplorers_NewExplorer _
(ByVal Explorer As Explorer)
End Sub

Public Sub m_objExplorer_FolderSwitch()
End Sub
/ExplEvents

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
. ..
Michael,

I moved all my code out of ThisOutlookSession except for the event handler
below:

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
'm_explevents.m_objExplorer_FolderSwitch
End Sub

I removed the folder Switch event handler because as you mentioned, it's
typically private on the explevents class moduel which I changed back to
"Private".

The problem I have when setup this way is that this event does not fire at
all.

I'm going to try this with VSTO so will ping the VSTO newsgroup unless
you/others have some more detail instructions (if you have it working on
your end) on how to do this.

Thanks much for your efforts.

Rafael

Am Fri, 14 Jul 2006 19:41:12 -0400 schrieb Rafael1119:

From what I can see, only Application_Startup should be in
ThisOutlookSession, the rest in the ExplEvents class.

If that´s the case, please set a breakpoint (F9) on the

Public Sub m_objExplorer_FolderSwitch()

line (which is Private by default, not Public) and see is the execution
stops there. As long as you do not switch explorers, but folders, it
should
do so.

For being able to switch also between explorers you need to have a class
module for each explorer.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
Well, here what my code looks like now in the "ThisOutlookSession" but

still
no joy. It fires during OL startup only.

Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
m_explevents.m_objExplorer_FolderSwitch
End Sub


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 m_colExplorers_NewExplorer _
(ByVal Explorer As Explorer)
Set m_objExplorer = Explorer
End Sub

Public Sub m_objExplorer_FolderSwitch()
Set myOlApp = 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
MsgBox myType
If myType = 0 Then
'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




Am Thu, 13 Jul 2006 19:40:09 -0400 schrieb Rafael1119:

Please look at your code: There´re two Application_Startup procedures.
Only
the first one, in ThisOutlookSession, will be called by Outlook.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
What do you mean by "move the code from the second Application_Starup
to
the
first one"? I know it must be simple but I don't see what you mean.

Rafael

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move

the
code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")
by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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

  #9  
Old July 17th 06, 11:51 AM posted to microsoft.public.outlook.program_vba
Rafael1119
external usenet poster
 
Posts: 5
Default ThisOutlookSession - code runs only once


"Michael Bauer" wrote in message
.. .
By Michael I think I've got it... Thanks Michael, it works like a charm.

Regards,

Rafael



Am Sat, 15 Jul 2006 10:03:43 -0400 schrieb Rafael1119:

I didn´t ask you to remove the FolderSwitch event procedure. So this is
what
you need to have at least and where it should be located:

Now I see another error: Because you declare m_explevents within
Application_Startup it terminates as soon as the execution leaves that
procedure. Due to that you don´t have any event handlers.

Instead declare that variable also on the module level as shown:

ThisOutlookSession
Private m_explevents As ExplEvents

Private Sub Application_Startup()
Set m_explevents = New ExplEvents
End Sub
/ThisOutlookSession

ExplEvents
Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer

Public Sub InitExplorers(objApp As Outlook.Application)
End Sub

Public Sub DeRefExplorers()
End Sub

Private Sub m_colExplorers_NewExplorer _
(ByVal Explorer As Explorer)
End Sub

Public Sub m_objExplorer_FolderSwitch()
End Sub
/ExplEvents

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
. ..
Michael,

I moved all my code out of ThisOutlookSession except for the event
handler
below:

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
'm_explevents.m_objExplorer_FolderSwitch
End Sub

I removed the folder Switch event handler because as you mentioned, it's
typically private on the explevents class moduel which I changed back to
"Private".

The problem I have when setup this way is that this event does not fire
at
all.

I'm going to try this with VSTO so will ping the VSTO newsgroup unless
you/others have some more detail instructions (if you have it working on
your end) on how to do this.

Thanks much for your efforts.

Rafael

Am Fri, 14 Jul 2006 19:41:12 -0400 schrieb Rafael1119:

From what I can see, only Application_Startup should be in
ThisOutlookSession, the rest in the ExplEvents class.

If that´s the case, please set a breakpoint (F9) on the

Public Sub m_objExplorer_FolderSwitch()

line (which is Private by default, not Public) and see is the execution
stops there. As long as you do not switch explorers, but folders, it
should
do so.

For being able to switch also between explorers you need to have a class
module for each explorer.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
Well, here what my code looks like now in the "ThisOutlookSession" but
still
no joy. It fires during OL startup only.

Private WithEvents m_colExplorers As Outlook.Explorers
Private WithEvents m_objExplorer As Outlook.Explorer

Private Sub Application_Startup()
Dim m_explevents As New ExplEvents
m_explevents.InitExplorers Application
m_explevents.m_objExplorer_FolderSwitch
End Sub


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 m_colExplorers_NewExplorer _
(ByVal Explorer As Explorer)
Set m_objExplorer = Explorer
End Sub

Public Sub m_objExplorer_FolderSwitch()
Set myOlApp = 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
MsgBox myType
If myType = 0 Then
'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




Am Thu, 13 Jul 2006 19:40:09 -0400 schrieb Rafael1119:

Please look at your code: There´re two Application_Startup procedures.
Only
the first one, in ThisOutlookSession, will be called by Outlook.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


"Michael Bauer" wrote in message
...
What do you mean by "move the code from the second Application_Starup
to
the
first one"? I know it must be simple but I don't see what you mean.

Rafael

Am Wed, 12 Jul 2006 23:08:48 -0400 schrieb Rafael1119:

Application_Startup is usefull only in ThisOutlookSession. So move

the
code
from the second Application_Startup to the first one.

Additionally please replace
Set myOlApp = CreateObject("Outlook.Application")
by
Set myOlApp = Application

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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:09 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.