How to determine when I switch from mail to calendar etc.

Status
Not open for further replies.

tcbme

Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
Four basic things, Mail, Calendar, People, and Tasks; How do I detect in VBA code when I switch from one to another. Doesn't really matter which one ones. I am guessing that I have to create a wrapper with the appropriate events in it but I have not been able to figure out which event I am looking for. I know how to create the wrapper etc., just not sure what event I should be looking for.
 
Are you switching folders or items (forms)? If you are using simple objects rather than specific item or folder types you'll need to test the folder type with if statements (probably other ways too).

To test items you can using methods such as

> Class = olMail (43)

InStr(1, .MessageClass, "IPM.Note") > 0

TypeName(Object) = "MailItem"

You can use DefaultItemType with folders.
 
I guess part of the problem is that I am not sure what I am switching so I am not really sure what the correct question is. Have only been writing code for Outlook for about a year so I still have a lot of learning to do. What I am really trying to accomplish: I am writing an addin that will require a button on the "Standard" command bar. I know how to add the button and get it to execute my code. What I am not sure of is how to make sure that the button is only visible when I am looking at the calendars (folders I think). Not individual individual calendar items. I was working under the assumption that there was only (normally) one explorer object and that there was an event that I use to determine when a user swithed to looking at calendars.

Also is my assumption that under normal circumstances is there only 1 explorer item for the life of a session correct, or is the existing explorer disposed and a new one created when you switch from say calendars to mail?
 
One explorer per session if i understand the question correctly. I'll see if i can dig up some code that does what you need.
 
Diane, thanks for the reply. Sorry if the questions were a bit unclear. Have a few questions about terminology if you don't mind. Sorry if these sound a little silly. Asking these now so I can make future questions more clear and I am sure there will be more questions. 1) When I first open outlook I get a list of folders on the left (inbox, outbox, etc. and pst folders) and the list of individual email messages in my inbox on the right. I have always thought the left part was referred to as the navigation pane but I don't know what the right part is supposed to be called. 2) Is the left part referred to as the navigation pane? 3) What is the 'name' of the part where the individual email messages are listed? I have essentially the same questions about the proper names to use when looking at Calendars and Tasks. 4) Could just point me to a basic tutorial that would explain the correct names and terminology? I'll be glad to do the reading and not waste yours or anyone else's time.
 
The list of messages is called the... Message list. That center pane in general is called "Information pane" but I don't think "real people" call it that, only people inside Microsoft. :) For calendar and contacts, most people just call the information pane simply calendar or contacts.

The pane on the left with the folders is called the Navigation pane. The buttons at the bottom open the individual modules - but if you refer to them as mail pane, task pane, contact pane, no one will complain... the Folder module can be called the Folder list.

In Outlook 2013, the bar with the module names (or the buttons if you use compact) is the Folder Bar.
 
After some more digging it appears that I can use the explorer object's BeforeFolderSwitch, ViewSwitch, or FolderSwitch events with some additional logic to decide when to enable the button and make it visible. I am leaning towards the ViewSwitch event. Does this sound like the corrrect approach?
 
viewswitch would look for changes in the view - like switching from Messages to messages with preview. If you want to detect which module, I'd use ModuleSwitch and test for the module
If CurrentModule.NavigationModuleType = olModuleCalendar Then
' whatever

while not what you are doing, the macros at http://www.slipstick.com/developer/code-samples/select-multiple-calendars-outlook/ might point you in the right direction.

That will identify when you are in the module (although won't be of help when using the folder list.) Hmm. Maybe testing the folder type might be better - this is usually done by check the default item type - if ipm.appointment, it's a calendar. I'll see if i can find a code sample.
 
DefaultItemType is what you want to test.

if fldr.DefaultItemType = olAppointmentItem then

'whatever
 
Diane, Thanks for the tip on the ModuleSwitch event; exactly what I needed. Right now all is does is toss up a messagebox with the name of the module, but at least I know it is working. I still need to add my "real" code to hide and unhide the button based on the module but that shouldn't be to hard; simple for loop on each of the buttons looking for the right one and setting .visible either true or false depending on the module name.

Thanks so much for the help. Consider this one solved.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
oliv- determine to which address an email has been sent Outlook VBA and Custom Forms 3
M How can I determine which user read an email Exchange Server Administration 4
A Rules - how to determine if all conditions in rule are true or false Outlook VBA and Custom Forms 5
M How does Outlook determine item numbers in a folder? Outlook VBA and Custom Forms 3
A account hacked, need software to determine what emails have been sent Using Outlook 1
J VBA code to determine 'show' state of SearchBar Using Outlook 7
L Outlook Meeting Response: determine when a meeting response has been edited Using Outlook 1
M RDO: using TypeOf to determine [OOM] Class Outlook VBA and Custom Forms 1
S How to determine if message will be encrypted on Send Outlook VBA and Custom Forms 1
T Can I determine if an item is in a shared calendar? Outlook VBA and Custom Forms 5
T How to determine if email address resides in Exchange w/o OutlookSecurity prompts? Outlook VBA and Custom Forms 1
O Outlook - Switch from Exchange to IMAP Using Outlook 2
V Folder Properties - Gmail account can't switch Using Outlook 5
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
Commodore Automatic switch between working offline/online Using Outlook 4
e_a_g_l_e_p_i A few question before I decide to switch to Pop from imap Using Outlook 9
O How to recover rules after switch from POP3 to IMAP Using Outlook 2
E Accessing shared outlook folder doesn't work since switch to new outlook/excel Outlook VBA and Custom Forms 11
D Outlook 2016: /altvba startup switch does not work Using Outlook 2
J VBA to switch Outlook online/offline Outlook VBA and Custom Forms 4
George Simpson "Switch to HTML" in Outlook 2016 notes field Using Outlook 1
B Switch template with account Outlook VBA and Custom Forms 3
P How to switch back from Outlook 2010 to Outlook 2007? Using Outlook 3
B Outlook 2010: using /altvba switch Using Outlook 1
E Should I switch to IMAP? Using Outlook 0
wisedave Switch from POP3 over to IMAP Using Outlook 3
K Can Outlook be launched with the /cleanreminders switch multiple times? Using Outlook 2
W How to switch my list view back to normal view Using Outlook 1
E Should I switch to redemption Outlook VBA and Custom Forms 11
E Should I switch to redemption Outlook VBA and Custom Forms 11
M Switch Mail format Outlook VBA and Custom Forms 6
U Using /a switch to send multiple files? Outlook VBA and Custom Forms 1
L Error when exporting Sent Mail to Excel Outlook VBA and Custom Forms 6
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
K How can I delete an e-mail from Outlook Using Outlook 1
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
A Macro Mail Alert Using Outlook 4
e_a_g_l_e_p_i MY Outlook 2021 changed the format of the shortcuts for mail, calendar etc. Using Outlook 10
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
P What is your strategy for dealing with SPAM and Junk Mail? Using Outlook 1
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
T 1:1 Datatransfer from incoming mail body to customs form body Outlook VBA and Custom Forms 0
O Mail rule issue Using Outlook 3
A manual rule sends mail to wrong folder Using Outlook 5
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
D Outlook 2003 Mail Fails Using Outlook 1

Similar threads

Back
Top