[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do I reference a calendar other than the default calendar?

Posted on 2010-09-15
2
Medium Priority
?
323 Views
Last Modified: 2012-06-27
I am exporting the events from one day into a table in a Word document. I have not found a way to reference a calendar at the root of a mailbox besides the default calendar. Every method I find online doesn't quite work. Here are the lines that I think need to be changed:

Set wrdDoc = wrdApp.Documents.Add
Set MyOutlookNS = GetNamespace("MAPI")
Set myItems = MyOutlookNS.GetDefaultFolder(olFolderCalendar).Items

i know this code is not documented well, somewhat messy, and it is probably not wise to put so much code under a button click. The only part that is really of concern for this question is the beginning from the Dim statements through the Set statements.

Private Sub CommandButton1_Click()

Dim MyOutlookNS As Outlook.NameSpace
Dim targetDate As Date
Dim comparisonDate As Date
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim myItems As Outlook.Items
Dim myRange As Range
Dim X, Y As Integer

Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add
Set MyOutlookNS = GetNamespace("MAPI")
Set myItems = MyOutlookNS.GetDefaultFolder(olFolderCalendar).Items
Set myRange = wrdDoc.Content

targetDate = Now

myItems.Sort "[Start]", False

   wrdDoc.Paragraphs.SpaceAfterAuto = 0
   wrdDoc.Paragraphs.Format.SpaceAfter = 0
   wrdDoc.Paragraphs.LineSpacingRule = wdLineSpaceSingle
With myRange

   .ParagraphFormat.Alignment = wdAlignParagraphLeft
   .Font.Size = 24
   .Font.Bold = True
   .InsertAfter targetDate & vbCrLf

   .Collapse wdCollapseEnd
   .Tables.Add myRange, 1, 2
   .Tables(1).TopPadding = 0
   .Tables(1).BottomPadding = 0
   .Tables(1).LeftPadding = 0
   .Tables(1).RightPadding = 0
   .Tables(1).Spacing = 0

X = 1
Y = 1

For Each MyAppt In myItems
   comparisonDate = MyAppt.Start
   If Mid(comparisonDate, 1, 9) = Mid(targetDate, 1, 9) Then
       
       .Tables(1).Cell(X, Y).Range.Text = Format(MyAppt.Start, "Medium Time") & " - " & Format(MyAppt.End, "Medium Time")
       .Font.Bold = True
       .Tables(1).Cell(X, Y + 1).Range.Text = MyAppt.Subject & " - " & MyAppt.Location & vbCrLf & MyAppt.Body
       
       

       .Tables(1).Rows.Add
       X = X + 1

   End If
Next
.Tables(1).Rows.Last.Delete
End With

wrdApp.Visible = True

End Sub

Open in new window

0
Comment
Question by:jjh2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 1000 total points
ID: 33690979
As you stated, there is very little documentation out there.  I managed to find the following instructions from Sue Mosher [MVP-Outlook].  Hope it helps.


To create a new item in a non-default folder programmatically, use the =
Add method on the target folder's Items collection:

Set newItem =3D targetFolder.Items.Add("IPM.Post.YourFormName")

The message class parameter is optional.=20

To create an item in another person's Calendar folder in an Exchange =
mailbox, use Namespace.GetSharedDefaultFolder to get the target =
MAPIFolder. Otherwise, you can use the code at =
http://www.outlookcode.com/d/code/getfolder.htm to walk the folder =
hierarchy and return the MAPIFolder corresponding to a given path =
string.
0
 
LVL 38

Assisted Solution

by:puppydogbuddy
puppydogbuddy earned 1000 total points
ID: 33691207
This link has code snippets with explanations that should help clarify things, but you have to read it in its entirety:
            http://www.eggheadcafe.com/software/aspnet/30128430/adding-appointment-to-non-default-calendar.aspx
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

650 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