Keith
Set olFldr = olApp.GetFolderFromID("MAPIFolder") '<--errors out
I've never used GetFolderFromID, but I'll hazard a guess that there's not
folder with the id "MAPIFolder". olFolderCalendar is a constant that's
built into the Outlook library. If you don't use the library (i.e. you're
late binding), then you just need to use the intrinsic value of that
constant. Go to the Immediate Window with a reference set as if you're
early binding and type in
?olFolderCalendar
9
Now go back to your sub and put this at the top (under your Dim statements)
Const olFolderCalendar As Long = 9
When you get rid of the reference, you'll have a constant in your procedure
that you can use just like the built-in one. With the addition of the Const
in your code, the early bound and late bound code for that line will be
exactly the same.
It looks like you're going to run into a problem on the next line because
getappointmentitem isn't a method of the MAPIFolder object, or any other
object of which I'm aware.
Here's my late bound conversion checklist. I don't know if it's complete,
but it has worked for me so far
a.. Change all declarations from Outlook objects to the generic Object
data type
b.. Change Set statements to GetObject or CreateObject
c.. Change any built-in constants to their intrinsic values
d.. Add optional arguments that have a default value
It can be found at
http://www.dicks-clicks.com/excel/ol...sion_Checklist
One other thing to note. In your EB code, you declare olApt as
AppointmentItem and in your LB code it's Object. A problem that I have run
into is when there's a different kind of Outlook item in the folder. You
should check the type of that object
For Each olApt in olFldr.Items
If TypeName(olApt) = "AppointmentItem" Then
'Do your stuff
End If
Next olApt
It happens so rarely that I don't even remember the specifics of the problem
I encountered, but it will happen to one of your users if you don't test for
it. The problem is that the Object data type will pick up any type of
Outlook item, but will crash when it gets to a property, like Start, that
doesn't relate to the object at hand.
--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com
KR wrote:
I'm (for the first time) developing a cross-office mini-app that
includes OL; this is also the first time I've been in an environment
where different levels of the libraries are co-existing, requiring me
to use late binding. So far, I like early binding a lot better :-/
I'm trying to get appointment information from OL using late binding.
I've used intellisense with the library referenced, and also explored
(to my limited understanding) the OL object model via OL VBA.
Unfortunately, no matter what I do, once I try to run my late binding
code, it get "object doesn't support this property or method" errors,
and I haven't been able to figure out what the heck I'm doing wrong.
So, I'm posting the relevant section of my code below, with hat in
hand, hoping someone can lend some syntax help. I appreciate any help
you can offer... if you want to be my hero, please also provide
suggestions on syntax to get the appointment subject, start date, end
date, and duration as well... I haven't even gotten that far yet...
Keith
==========================================
'for late binding:
Dim olApp As Object
Dim olNs As Object
Dim olFldr As Object
Dim olApt As Object
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olApp.GetFolderFromID("MAPIFolder") '<--errors out
Set olApt = olFldr.getappointmentitem("olFolderCalendar")
'for early binding
' Dim olApp As Outlook.Application
' Dim olNs As Namespace
' Dim olFldr As MAPIFolder
' Dim olApt As AppointmentItem
' Set olApp = New Outlook.Application
' Set olNs = olApp.GetNamespace("MAPI")
' Set olFldr = olNs.GetDefaultFolder(olFolderCalendar)
'***** Pull all outlook data into an array *****
For Each olApt In olFldr.Items
If InStr(1, olApt.Subject, "Vacation", vbTextCompare) 0 Then
If Year(olApt.Start) = 2005 Then
MyDur = olApt.Duration / 60
If MyDur 8 Then MyDur = 8
' UseRow = Format(olApt.Start, "mm")
eachmonth = Val(Format(olApt.Start, "mm"))
ThisDay = Val(Format(olApt.Start, "dd"))
'LastDay = Val(Format(olApt.End, "dd"))
'Gives starting row position
PasteMonthStartRow = 16 * ((eachmonth - 1) \ 3) + 17
'gives 1, 2, or 3 for the column grouping
PasteMonthStartColumn = (eachmonth Mod 3)
If PasteMonthStartColumn = 0 Then
PasteMonthStartColumn = 3 'Gives the number of the
actual start column PasteMonthStartColumn =
((PasteMonthStartColumn - 1) * 7) + 1
OffsetX = (((MAdjArray(eachmonth)) + (ThisDay - 1)) \
7) * 2 OffsetY = ((MAdjArray(eachmonth)) + (ThisDay -
1)) Mod 7
PasteMonthRow = PasteMonthStartRow + OffsetX
PasteMonthColumn = Trim(Chr((PasteMonthStartColumn +
OffsetY) + 64))
With oWrkSht
.Activate
.Range(PasteMonthColumn & PasteMonthRow).Select
Selection.Value = MyDur
Selection.AddComment (olApt.Subject)
End With
'MsgBox "Appt found:" & Chr(13) & Format(olApt.Start,
"mm/dd/yy") & Chr(13) & _
' "'" & PasteMonthColumn & "' '" &
PasteMonthRow & "'" & Chr(13) & _
' "'" & PasteMonthStartColumn & "' '" &
PasteMonthAddColumns & "'" & Chr(13) & _
' "'" & PasteMonthStartRow & "' '" &
PasteMonthAddRows & "'" & Chr(13)
'Debug.Print olApt.Subject, MyDur, Format(olApt.Start,
"mm/dd/yy")
End If
End If
Next olApt
Set olApt = Nothing
Set olFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing