Question About ThisOutlookSession

  • Thread starter Thread starter Richard Winston
  • Start date Start date
R

Richard Winston

I bought Sue Mosher's book (Jumpstart for Admins...good stuff) and have
been working through some of the modules up through chapter 4. I put
all the subroutines in their own module files so there is no code in
ThisOutlooksession.


When I go to run the macros I get a "Sub or Function Not Defined" dialog
and ThisOutlookSession is highlited, which I guess means it's looking
for the module there. I made the subroutines Public but that didn't
change anything.


I guess I'm not understanding why this is happening and also not really
understanding the role of ThisOutlookSession in the grand scheme of
things. If someone could help me out with that I'd really appreciate it.

Thanks.
 
ThisOutlookSession is actually a class module with an intrinsic Application object already defined. Its Application_Startup event handler is a good place to initialize any other VBA classes that you want to use to monitor Outlook events.

About the macros you created, are they in regular modules or class modules? Feel free to post one of them that isn't working.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Sue said:
ThisOutlookSession is actually a class module with an intrinsic Application object already defined. Its Application_Startup event handler is a good place to initialize any other VBA classes that you want to use to monitor Outlook events.

About the macros you created, are they in regular modules or class modules? Feel free to post one of them that isn't working.


They are all regular modules. Here's the CreateOneWeekTask moodule:


Public Sub CreateOneWeekTask()
Dim objApp As Outlook.Application
Dim objTask As TaskItem

Set objApp = CreateObject("Outlook.Application")
Set objTask = objApp.CreateItem(olTaskItem)

objTask.StartDate = Date
objTask.DueDate = Date + 7
objTask.Display

Set objApp = Nothing
Set objTask = Nothing
End Sub



It's pretty much the same as in your book. I just added the Dim
statements to invoke the Auto List Members functionality.


Since I'm not doing anything with Outlook events, there is no need for
me to do any initialization in ThisOutlookSession for this particular
module, is that right ?
 
You're right, there's nothing at all in your macro that should be trying to access anything in ThisOutlookSession. I think I've seen this problem once before, a long time ago, but don't recall how I fixed it. Maybe it's just a matter of restating Outlook.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Sue said:
You're right, there's nothing at all in your macro that should be trying to access anything in ThisOutlookSession. I think I've seen this problem once before, a long time ago, but don't recall how I fixed it. Maybe it's just a matter of restating Outlook.


Sue, I noticed a couple of things:

1) When I place the subs in their own named modules, Outlook immediately
asks me if I want to enable/disable macros when I launch it. When I
place the subs in ThisOutlookSession, that dialog only comes up when I
bring up the macros via the toolbar.

2) When the subs are in their own named modules, I get the "Sub not
found..." message the first time I try to run. Subsequent to that, I am
able to run them.


There definitely appears to be an initialization problem when I put the
subs in their own named modules.


I can obviously just leave the subs in ThisOutlookSession but

a) that doesn't help me understand what is going on, which would help me
understand how Outlook works and

b) when I get to the part of your book that gets into the interesting
stuff (working with events), I don't want ThisOutlooksession all
cluttered up.
 
Richard said:
Sue, I noticed a couple of things:

1) When I place the subs in their own named modules, Outlook immediately
asks me if I want to enable/disable macros when I launch it. When I
place the subs in ThisOutlookSession, that dialog only comes up when I
bring up the macros via the toolbar.

2) When the subs are in their own named modules, I get the "Sub not
found..." message the first time I try to run. Subsequent to that, I am
able to run them.


There definitely appears to be an initialization problem when I put the
subs in their own named modules.


I can obviously just leave the subs in ThisOutlookSession but

a) that doesn't help me understand what is going on, which would help me
understand how Outlook works and

b) when I get to the part of your book that gets into the interesting
stuff (working with events), I don't want ThisOutlooksession all
cluttered up.



Sue, I think I found out what the problem is:


The module name can't be the same name as the subroutine name.


I have no idea why that causes the problem but changing the module name
to anything but the subroutine name allows the macros to be run without
problem. I guess I'm polluting the namespace (?!?)


Pheewwwwww !!!!
 
Back
Top