A
Alan
Hi All,
I am trying to write some code that will make a copy of all extant
calendar items in a given folder to another calendar folder.
I have the code below, but Outlook doesn't seem to want to allow me to
move the collection of items to the new folder (I have added a comment
in the code just above the offending line).
Is there a simple way around this?
As an aside, am I correct in deleting the first indexed item
repeatedly in order to clear the destination calendar before
re-populating? My reasoning is that if there are 10 items in there to
start with, after deleting the first, there are only nine (indexed 1
to 9) so the code would fall over halfway through the loop if I didn't
do it that way?
Thanks,
Alan.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Sub CopyMainCalItemsToExchangeFolder()
Dim FolderCollection As Folders
Dim AlanMainMailFileFolders As Folders
Dim AlanCalendarItems As Items
Dim AlanExchangeFolders As Folders
Dim AlanExchangeCalendarItems As Items
Set FolderCollection = Application.GetNamespace("MAPI").Folders
Set AlanMainMailFileFolders = FolderCollection("Alan - Main Mail
File").Folders
Set AlanCalendarItems = AlanMainMailFileFolders("Calendar").Items
Set AlanExchangeFolders = FolderCollection("Mailbox - Alan
Figgins").Folders
Set AlanExchangeCalendarItems = AlanExchangeFolders("Calendar").Items
TotalItems = AlanExchangeCalendarItems.Count
For Counter = 1 To TotalItems
AlanExchangeCalendarItems(1).Delete
Next Counter
Set CopiedItems = AlanCalendarItems
' This is the line that causes the problem, with the collection of
items not supporting the move method
CopiedItems.Move AlanExchangeFolders("Calendar")
End Sub
I am trying to write some code that will make a copy of all extant
calendar items in a given folder to another calendar folder.
I have the code below, but Outlook doesn't seem to want to allow me to
move the collection of items to the new folder (I have added a comment
in the code just above the offending line).
Is there a simple way around this?
As an aside, am I correct in deleting the first indexed item
repeatedly in order to clear the destination calendar before
re-populating? My reasoning is that if there are 10 items in there to
start with, after deleting the first, there are only nine (indexed 1
to 9) so the code would fall over halfway through the loop if I didn't
do it that way?
Thanks,
Alan.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Sub CopyMainCalItemsToExchangeFolder()
Dim FolderCollection As Folders
Dim AlanMainMailFileFolders As Folders
Dim AlanCalendarItems As Items
Dim AlanExchangeFolders As Folders
Dim AlanExchangeCalendarItems As Items
Set FolderCollection = Application.GetNamespace("MAPI").Folders
Set AlanMainMailFileFolders = FolderCollection("Alan - Main Mail
File").Folders
Set AlanCalendarItems = AlanMainMailFileFolders("Calendar").Items
Set AlanExchangeFolders = FolderCollection("Mailbox - Alan
Figgins").Folders
Set AlanExchangeCalendarItems = AlanExchangeFolders("Calendar").Items
TotalItems = AlanExchangeCalendarItems.Count
For Counter = 1 To TotalItems
AlanExchangeCalendarItems(1).Delete
Next Counter
Set CopiedItems = AlanCalendarItems
' This is the line that causes the problem, with the collection of
items not supporting the move method
CopiedItems.Move AlanExchangeFolders("Calendar")
End Sub