C
Culverin
Hello:
I'm developing a macro that will delete every unused appointment item in a
mailbox that is older than today.
The appointment items are from a custom form. There's a memory management
problem I don't understand and am
unable to solve. Stepping through the code using the Script Debugger, I see
the code for the custom form for
a few steps when the assignment statement for "DeleteDate" executes (line
(A)). I think that an instance of
the form is created in memory whenever a property of the custom form is
referenced for the first time. Since
"TZStartTime" is a custom field on the form, Outlook must place the item in
memory. When this happens, about
1.5K to 2.3K of memory is used. However, I have been unable to determine
how to release this memory when
execution of the While/Wend loop goes to the next item. Consequently,
system memory gets used up rather quickly.
I have 42,000 items to process and can never get past about 1,800.
If I comment out line (A), I see the same thing happening on line (B) for an
item delete. I believe that the
appointment item form must be placed memory before deletion.
This is my first VBA macro for Outlook and I'm hoping that someone will be
able to explain what is happening and
how to release the memory. Any help will be greatly appreciated. Thank you.
Here's the relevant code:
..
..
..
On Error Resume Next
Set nns = Application.GetNameSpace("MAPI")
Set CTL = GetInspector.ModifiedFormPages("Delete Unused Appointments")
Set MyMailbox = nns.Folders("Mailbox -
NAT-CSD-Appointments").Folders("Offices").Folders()
OfficeCount = MyMailbox.Count
For IXA = 1 to OfficeCount
Set MyOffices = nns.Folders("Mailbox -
NAT-CSD-Appointments").Folders("Offices").Folders(IXA).Folders()
CalendarCount = MyOffices.Count
For IXB = 1 to CalendarCount
Set MyCalendars = nns.Folders("Mailbox -
NAT-CSD-Appointments").Folders("Offices").Folders(IXA).Folders(IXB)
ItemCount = MyCalendars.Items.Count
IXC = 1
IXD = 0
While ItemCount > IXD
(A) DeleteDate = MyCalendars.Items(IXC).UserProperties("TZStartTime")
NumDays = DateDiff("d", DeleteDate, Now)
ItemStatus = MyCalendars.Items(IXC).BusyStatus
If NumDays > 0 And ItemStatus = 0 Then
(B) MyCalendars.Items(IXC).Delete
Else
IXC = IXC + 1
End If
IXD = IXD + 1
Wend
Set MyCalendars = Nothing
Next
Set MyOffices = Nothing
Next
..
..
..
I'm developing a macro that will delete every unused appointment item in a
mailbox that is older than today.
The appointment items are from a custom form. There's a memory management
problem I don't understand and am
unable to solve. Stepping through the code using the Script Debugger, I see
the code for the custom form for
a few steps when the assignment statement for "DeleteDate" executes (line
(A)). I think that an instance of
the form is created in memory whenever a property of the custom form is
referenced for the first time. Since
"TZStartTime" is a custom field on the form, Outlook must place the item in
memory. When this happens, about
1.5K to 2.3K of memory is used. However, I have been unable to determine
how to release this memory when
execution of the While/Wend loop goes to the next item. Consequently,
system memory gets used up rather quickly.
I have 42,000 items to process and can never get past about 1,800.
If I comment out line (A), I see the same thing happening on line (B) for an
item delete. I believe that the
appointment item form must be placed memory before deletion.
This is my first VBA macro for Outlook and I'm hoping that someone will be
able to explain what is happening and
how to release the memory. Any help will be greatly appreciated. Thank you.
Here's the relevant code:
..
..
..
On Error Resume Next
Set nns = Application.GetNameSpace("MAPI")
Set CTL = GetInspector.ModifiedFormPages("Delete Unused Appointments")
Set MyMailbox = nns.Folders("Mailbox -
NAT-CSD-Appointments").Folders("Offices").Folders()
OfficeCount = MyMailbox.Count
For IXA = 1 to OfficeCount
Set MyOffices = nns.Folders("Mailbox -
NAT-CSD-Appointments").Folders("Offices").Folders(IXA).Folders()
CalendarCount = MyOffices.Count
For IXB = 1 to CalendarCount
Set MyCalendars = nns.Folders("Mailbox -
NAT-CSD-Appointments").Folders("Offices").Folders(IXA).Folders(IXB)
ItemCount = MyCalendars.Items.Count
IXC = 1
IXD = 0
While ItemCount > IXD
(A) DeleteDate = MyCalendars.Items(IXC).UserProperties("TZStartTime")
NumDays = DateDiff("d", DeleteDate, Now)
ItemStatus = MyCalendars.Items(IXC).BusyStatus
If NumDays > 0 And ItemStatus = 0 Then
(B) MyCalendars.Items(IXC).Delete
Else
IXC = IXC + 1
End If
IXD = IXD + 1
Wend
Set MyCalendars = Nothing
Next
Set MyOffices = Nothing
Next
..
..
..