K
KR
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
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