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.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 

tcbme

Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
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?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 

tcbme

Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
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.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 

tcbme

Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
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?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
DefaultItemType is what you want to test.

if fldr.DefaultItemType = olAppointmentItem then

'whatever
 

tcbme

Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
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 Determine if a public Folder is used by an Application Using Outlook 2
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 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
H The default e-mail account keeps switching to another account. I have to manually switch it back everytime I open Outlook. Using Outlook 2
B Outlook 2007 is very slow to switch between mail, contacts, and calendar. Using Outlook 2
M It takes a long time to switch between mailbox, tasks, contacts. Using Outlook 4
L Outlook 2007 slow to switch view from one folder to another Using Outlook 8
J Outlook 2010 Microsoft exchange server to pop account type switch? Using Outlook 2
B Re: Export/Import/Switch from WLM to Outlook Using Outlook 1
T Auto Switch Back? Using Outlook 3
J How to switch users using Outlook 2003 Using Outlook 5
J How to switch between two email addresses when sending emails? Using Outlook 3
P Re: Outlook 2007 hang / stop responding when switch language from English to Thai Using Outlook 2
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 Correct E-Mail Pulling Wrong Mail Using Outlook 5
S Outlook mail adressing stops after first match in GAL Using Outlook 0
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
MrMayor SENT mail not reloading to top?? Using Outlook 4
Terry Sullivan Sender Field Displays My E-Mail Address, Not My Name Using Outlook 1
ThinkToday Calculate reply time of outlook mail Using Outlook 1
B Outlook 2010 Opening Mail Attachment Using Outlook 2
e_a_g_l_e_p_i Is it possible it set the fonts used to read incoming mail Using Outlook 25
D Mail in Sent Items Gone Using Outlook 12
M Managing Gmail "All Mail" sync issues with IMAP Using Outlook 1

Similar threads

Top