Solved

Opening Outlook 2003 profile using VBScript.

Posted on 2008-10-21
5
838 Views
Last Modified: 2012-05-05
Hi,
I want to use standalone VBSCRIPT to open an outlook mailbox. After opening it I will excute VBScript code shown below to close that outlook mailbox. Here's the code I'm using, please let me know where I am going wrong.  

opening Outlook mailbox code - NOT WORKING
_______________________________________________________________
Set objOutlook = CreateObject("Outlook.Application")      ' Get Outlook
Set objNamespace = objOutlook.GetNamespace("MAPI")      ' Get MAPI
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)      ' Get inbox
_______________________________________________________________

Closing Outlook mailbox code - WORKING
_______________________________________________________________
Set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")
olMAPI.Application.Quit
Set olMAPI = Nothing
_______________________________________________________________

Thanks you for your help.
0
Comment
Question by:atskiii
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22777557
Hello atskiii,

Try replacing:
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)      ' Get inbox
with
Set objFolder = objNamespace.GetDefaultFolder(6)      ' Get inbox

Regards,

chris_bottomley
0
 

Author Comment

by:atskiii
ID: 22781842
Hi Chris,

Thank you for your help. I have replaced "olFolderInbox" with "6" and error message I used to get, "Could  not complete the operation. One or more parameter values are not valid." no longer appears. When executing the code with parameter value "6", nothing seems to happen. What does value "6" represent? I tried "5" because Inbox is the 5th folder in my mailbox. sorry for this silly question. I am new to VBscripting so all seems so obvious to ask.

Thank you for your help again.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22783451
In VBA the constant olFolderInbox has a value of 6.  VBS does not know the values for VBA constants hence the substitution.

Your snippet:

Set objOutlook = CreateObject("Outlook.Application")      ' Get Outlook
Set objNamespace = objOutlook.GetNamespace("MAPI")      ' Get MAPI
Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)      ' Get inbox

establishes a connection to outlook but you cannot see it, objoutlook.visible should render it visble ... if however you are merely doing some processing you would not need it to be visible hence any snippets you saw to create this code may not have needed the visibility of the application.

I could of course be wrong, but that's my first take on the matter, let me know how it goes.

Chris
0
 

Accepted Solution

by:
atskiii earned 0 total points
ID: 22791276
Hi Chris,

Thanks for your lead. Since we last spoke I have been playing and reading and I achived to open Outlook by using the code below, using the Shell command. It does what I wanted to do and I am happy. After opening Outlook I pause for 3000msec and I close it using the code below.
_______________________________________________
Set WSHShell = CreateObject("Wscript.Shell")
WSHShell.run "Outlook"
_______________________________________________

To close Outlook  I used the code from earlier
_______________________________________________
Dim olMAPI
Set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")
olMAPI.Application.Quit
Set olMAPI = Nothing
________________________________________________

Thanks again for your assistance with this.

Aleks
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22791392
Most disappointing, I have tested the answer I gave to the original code and indeed replacing the constant with a magic number works, the outlook application is opened and closed again afterwards ... the follow on question whilst not fully resolved was not in the original so closing the Q as self answered is I believe unfair, but for 100 points i'm not about to argue.

Chris
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Resolve DNS query failed errors for Exchange
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now