VBScript—Set Focus to Inbox

How can I write a simple VBscript to set focus to Inbox in Outlook? When working in another applicaiton, say, corelDraw, I would like to have a VBscript to jump to Inbox in Outlook instantly.

Armstrong
Hong Kong
armsysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bruintjeCommented:
Hello armsys,

you could try something like

- paste in notepad
- save as gotoInbox.vbs
- will error if outlook is not open yet

--------------
    Dim olApplication
    Dim olns
    Dim olFolder
    Dim olExplorer
       
    Set olApplication = GetObject(,"Outlook.Application")
    Set olns = olApplication.GetNamespace("MAPI")
    Set olFolder = olns.GetDefaultFolder(6)
    Set olExplorer = olApplication.ActiveExplorer
    Set olExplorer.CurrentFolder = olFolder
 
--------------

hope this helps a bit
bruintje
armsysAuthor Commented:
Hi bruintje,

Thanks a lot. It works almost. Actually I write Macro Scheduler scripts, which supports VBScript. Questions:
1. No, I doesn't jump (SetFocus) to Outlook from another application such as Word or FileMaker;
2. How could it be more flexible to switch to Tasks, Journal, contacts, Calendar, or any folder?

Definitely your solution is better than native Macro Scheduler script. The latter primarily simulates keyboard/mouse.

Armstrong
Hong Kong
bruintjeCommented:
you could change the script to

-------------------------
Dim olApplication
Dim olns
Dim olFolder
Dim olExplorer
Dim strInput        

strInput = InputBox("Enter Data")

Set olApplication = GetObject(,"Outlook.Application")
Set olns = olApplication.GetNamespace("MAPI")

Select Case Trim(strInput)
Case 6 'this is the inbox
  Set olFolder = olns.GetDefaultFolder(6)
Case 13 'this is the inbox
  Set olFolder = olns.GetDefaultFolder(13)
Case 11 'this is the inbox
  Set olFolder = olns.GetDefaultFolder(11)
Case 9 'this is the calendar
  Set olFolder = olns.GetDefaultFolder(9)
Case 10 'this is the inbox
  Set olFolder = olns.GetDefaultFolder(10)
End Select

Set olExplorer = olApplication.ActiveExplorer
Set olExplorer.CurrentFolder = olFolder
olApplication.ActiveExplorer.Activate
-------------------------

you can find the appropriate id for the folders
- opening outlook
- with ALT+F11 going into the vb editor
- choose F12 to bring up the object inspector
- type in olFolder in the search box
- you'll get all properties and methods related
- click on one of them and the bottom will show you the id

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.