Help with Code!

  • Thread starter Thread starter -=Sojourn=-
  • Start date Start date
S

-=Sojourn=-

I had this code to switch my view every hour to the Outlook main screen;
but it no longer works /w Outlook 2003 - can anyone help?

Thanks in advance!

Dim iHour

Private Sub SwitchView()
If Hour(Now) <> iHour Then
Dim ctl As Office.CommandBarControl
Dim cbpop As Office.CommandBarPopup
Dim cb As Office.CommandBar

Set cb = Application.ActiveExplorer.CommandBars("Menu Bar")
Set ctl = cb.FindControl(ID:=5599, Recursive:=True)
ctl.Execute
iHour = Hour(Now)
Set ctl = Nothing
Set cb = Nothing
End If
End Sub
 
The actual switching of hte window... When I was running Outlook before
I upgraded to 2003, the window would switch from any view back to
Outlook Today. Now it doesn't.

Thanks!
Peter
 
So I don't have to look through the CommandBar ID enums, maybe you could
also tell us which command corresponds to 5599.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Well looked online... and have no idea what 5599 refers to :(

But in the last version of Outlook, it changed the view to Outlook Today
- does that help any?

Peter
 
Yes, 5599 indeed switches the current Explorer folder to the Outlook Today
folder.

What happens when you step through your code?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
When I step through the code I get:

Run-time error '91':

Object varialbe or With block varialbe not set.


Code:
If Hour(Now) <> iHour Then
Dim ctl As Office.CommandBarControl
Dim cbpop As Office.CommandBarPopup
Dim cb As Office.CommandBar

Set cb = Application.ActiveExplorer.CommandBars("Menu Bar")
Set ctl = cb.FindControl(ID:=5599, Recursive:=True)
ctl.Execute
iHour = Hour(Now)
Set ctl = Nothing
Set cb = Nothing
End If
 
Sue's on vacation.

Did you check to see if you are getting valid objects for cb and ctl?
 
I get a valid object for cb; but Nothing for ctl.

The error that comes up is Run-time error '91: Object variable or With
block variable not set.

But this code worked in Outlook XP, but is no longer working after
upgrading to Outlook 2003 - if that helps :(

Thanks
Peter
 
5599 is which menu item on which menu?

The menus have changed some in Outlook 2003, for example there is now a Go
menu. I'd look and see if what you are calling is located at the same menu
location in Outlook 2002 and 2003. I've had to make some calls to various
menu items code dependent on Outlook version. I test for that using
Outlook.Application.Version and store a global variable for the version that
I can access anywhere in my code. Then I use conditional code that branches
based on the version to get certain menu items.
 
In Outlook 2002 that menu command is in View, GoTo, Outlook Today. There is
no such menu item in Outlook 2003.

Outlook 2003 has a Go menu but that doesn't have an Outlook Today item.

You could manually customize the Outlook 2003 menus to add such a command
but the easiest way, and one that would work for both Outlook 2002 and 2003
is to directly go to the Outlook Today folder.

Since Outlook Today is the top of store it is always the parent folder of
the Inbox folder. So the following code would do what I think you want:
Dim oExp As Outlook.Explorer
Dim oFolder As Outlook.MAPIFolder
Dim oOutlookToday As Outlook.MAPIFolder
Dim oNS As Outlook.NameSpace
Dim oOL As Outlook.Application

Set oOL = CreateObject("Outlook.Application")
Set oNS = oOL.GetNameSpace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
Set oOutlookToday = oFolder.Parent
Set oExp = oOL.ActiveExplorer
Set oExp.CurrentFolder = oOutlookToday
 
Back
Top