Creating public calendars in vb or vbscript.

C

cfong01

Anyone know how to create public calendars in vb or vbscript? I was
able to create public folders but not calendars.

cyk.
 
G

Guest

If you don't specify the folder type with the Folders.Add method, it defaults
to the same type as the parent folder. Use the olDefaultFolders enumeration;
with olDefaultFolderCalendar, you need to use 9 in VBScript:

Set myNewFolder = myFolder.Folders.Add("My Public Calendar", 9)
 
G

Guest

Bind it to the folder you want to create your folder under. Use:

NameSpace.GetDefaultFolder(18)

Where 18 is the constant number for
olDefaultFolders.olPublicFoldersAllPublicFolders. This will give you a top
level folder, and you can use myFolder = MAPIFolder.Folders("FolderName")
ad-infinitum to traverse the hierarchy to get a specific folder.

You can also use a function like this to retrieve a MAPIFolder object if you
know the full path:

'******************************************************************************
'Custom procedure: OpenMAPIFolder(ByVal strPath)
'Purpose: Return a MAPIFolder from Path argument
'Returns: MAPIFolder object
'******************************************************************************
Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder
On Error Resume Next

Dim objFldr As MAPIFolder
Dim strDir As String
Dim strName As String
Dim i As Integer
If Left(strPath, Len("\")) = "\" Then
strPath = Mid(strPath, Len("\") + 1)
Else
Set objFldr = Application.ActiveExplorer.CurrentFolder
End If
While strPath <> ""
i = InStr(strPath, "\")
If i Then
strDir = Left(strPath, i - 1)
strPath = Mid(strPath, i + Len("\"))
Else
strDir = strPath
strPath = ""
End If
If objFldr Is Nothing Then
Set objFldr = Application.GetNamespace("MAPI").Folders(strDir)
On Error GoTo 0
Else
Set objFldr = objFldr.Folders(strDir)
End If
Wend
Set OpenMAPIFolder = objFldr
End Function
 
C

cykill

sorry, i'm new to vb. i don't quite understand. let say i want to
create a calendar called "Chicago", what would the code be like? below
is my code to create a public folder.


Dim objFolder As Object
Dim szConnString As String
Dim oSysInfo As ActiveDs.ADSystemInfo
Dim szDomainDNSName As String
Dim szStorageName As String

' Get the domain name.
oSysInfo = New ActiveDs.ADSystemInfo
szDomainDNSName = oSysInfo.DomainDNSName

' Get the storage name.
szStorageName = "file://./backofficestorage/" + szDomainDNSName
+ "/"

' Create the folder.
szConnString = szStorageName + "public folders/Conferences/" +
szFolderName

Try
objFolder = CreateObject("CDO.Folder")
Catch f As Exception
System.Console.WriteLine("Error Creating Folder Object")
End Try

'Set the folder properties.
Try
With objFolder
.Description = "Root folder for " + szFolderName
.ContentClass = "urn:content-classes:folder"

..Fields("http://schemas.microsoft.com/exchange/outlookfolderclass") =
"IPF.Folders"
.Fields.Update()
.DataSource.SaveTo(szConnString)
End With
Catch e As Exception
Exit Try
objFolder = Nothing
oSysInfo = Nothing
End Try
 
C

cykill

thanks for that. but its pretty much the same thing as what i have
now, which is creating a public folder. i need to create public
calendars. it doesn't matter which method i use, outlook object or
cdoex, i just need to create public caledars programatically. any
ideas?
 
G

Guest

You have to specify the specific content class for a calendar with CDOEX:

urn:content-classes:calendarfolder:
http://msdn.microsoft.com/library/e...content-classes_calendarfolder.asp?frame=true

With the Outlook Object Model, you'd use:

Sub AddCalendarFolder()
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Dim myNewFolder As Outlook.MAPIFolder
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderCalendar)
Set myNewFolder = myFolder.Folders.Add("My Contacts")
End Sub
 
C

cykill

Thanks. I've tried your example and upon compiling, I get
outlook.application, outlook.namespace, outlook.mapifolder not defined.
Under references, i've added cdo, cdoexm, mapi and outlook. what else
do I need?
 
G

Guest

You can't mix and match the code! CDOEX is meant to run on the Exchange
Server, were Outlook shouldn't be installed so you wouldn't be able to use
the Outlook Object Model. What lead you to use CDOEX in the first place?
There's some background to your solution that I'm missing.
 
C

cykill

i think i have extra references in there that i don't need. but i'm
compiling the code in my workstation but running the exe file on an
exchange server. is there a way to do it with CDOEX? if not, you're
saying i can run that code on a computer where there's outlook?
 
G

Guest

Is there a reason why you need to run this code on the server? Regardless,
it's far easier to use VBA against the Outlook Object Model on a PC running
Outlook. Do not install Outlook on the Exchange Server.
 
C

cykill

No reason. but does this cause the code not to compile? I don't have
outlook and exchange in the same computer. I think I was putting a
bunch of references in, like cdoex and outlook, thus giving you the
idea that i'm running outlook and exchange on the same computer. i'm
stuck trying to get your code to compile.
 
G

Guest

If you have CDOEX listed as an available reference in the Outlook VBA Editor,
you've obviously registered a copy of cdosys.dll on that PC, so the project
should compile (unless the reference is listed as MISSING). If you're
running or compiling the code I gave you on the server, it won't work because
Outlook is not installed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top