Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to interface with two outlook calendars 1

Status
Not open for further replies.

Ayias

Technical User
Apr 1, 2004
9
GB
Hello. I am trying to write some VB Script code to interface with two outlook 2000 calendars. I can write the code to interface with one calendar fine, but I am unable to write the code to interface with more the one calendar. I have got code which does allow me to interface with two inboxs, but when I try to modify it to work with calendars instead it fails. On code 2 it fails on line 4 "object or property does not support this method"

Any ideas on if what I am doing is possible and if so, how I can get it to work?

CODE 1 - Code that does work and does interface with two mailboxes

Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, True, 0, True, "SERVER" & vbLf & "MAILBOX"
Set Inbox = oSession.Inbox
Set Messages = Inbox.Messages

CODE 2 - Code that attempts to interface with one of the calendars but fails

Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, True, 0, True, "SERVER" & vbLf & "MAILBOX"
Set Calendar = oSession.GetDefaultFolder(2)
Set Messages = Calendar.items
 
From the object browser:
Const olFolderCalendar = 9 ' and not 2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for that

I tried changing the value from 2 to 9. I now get a different error message:

Value 2 - Error on line 4 "obkect does not support this property or method 'calendar.items'

Value 9 - Error on line 3 "collaboration data objects"

Any further ideas?
 
Hello Ayias,

In outlook.application, it is olFolderCalendar=9.
In (cdo) mapi.session, it is ActMsgDefaultFolderCalendar=0.

In your case, use
Set Calendar = oSession.GetDefaultFolder(0)

Actually, I have no idea what you mean by 2 inboxes or 2 calendars!

regards - tsuji
 
Sorry still no joy.

Basically what I am doing is using vbscript to get data out of two mailboxes. I can get the data out of the inboxes no problem, but when I try to get data out of the calendar it does not work. If i use the default folder option it does work, but when I try to access the none default mailboxes calendar it does not work, but I can access inbox using this method
 
Ayias,

You have to check the object model. Speculate sometime is needed, but eventually, the actual documentation rules. The calendar does not have items collection, it has messages collection.
Code:
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, True, 0, True, "SERVER" & vbLf & "MAILBOX" 
Set Calendar = oSession.GetDefaultFolder(0)
Set Messages = Calendar.Messages
- tsuji
 
brilliant that worked, thank you all very much!
:)
 
Sorry to be a pain....

Although it now works, I am now unable to get any useful info out the code, what i need to get out of the calendar is the time and date the appointment starts, now that I am using messages instead of items, it now only gives me the subject of the meeting and it tells me that the start and end methods are not valid to use. Below is the code in question

for each message In Messages
msgbox (message.start)
msgbox (message.end)
next
 
Ayias,

Code:
for each message In Messages
    msgbox (message.starttime)
        msgbox (message.endtime)
next
- tsuji
 
Ayias, when in outlook goto VBE (Alt-F11) and open the object browser window (F2). Then feel free to play with the search feature and the F1 key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sadly I am using vbscript and not vba within outlook. As i need the code to run without outlook running, which has caused most of my problems as there is less help avaiable for vbscript. Ideally id like the full VB package, but my company will never pay for that

Thanks again tsuji, it now fully works. The little differences between vbscript/vb are annoying.
 
If you have Outlook installed, then you should have the VBEditor that is bundled with standard distributions of Office. This can be used as mentioned by PHV to explore the object model of any object that is registered. You can then ud=se this knowledge to write your code in VBScript using the appropriate object methods and attributes.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top