Я пытаюсь создать сценарий переноса элементов в существующем PST-файле (источник) в несколько новых PST-файлов (цель). По сути, я беру элементы в существующем PST и копирую элементы в новый файл PST в зависимости от года, когда элемент был получен / создан, но у меня возникают проблемы с копированием элементов из папки Deleted Items
в источнике PST в папку Deleted Items
в целевом PST.
Если я щелкну правой кнопкой мыши по элементу в исходном PST-файле, выберите Move
, затем выберите Copy to Folder
и выберите папку Deleted Items
в целевом PST элемент будет скопирован в новый файл PST независимо от типа / класса сообщения. Однако если я использую VBA для приведения объекта объекта к соответствующему типу, а затем к методу Copy
(или CopyTo
для AppointmentItem), я получаю ошибку Run-time error '13': Type mismatch
для объектов NoteItem и TaskItem.
Вот фрагмент кода, который не работает для объектов NoteItem и TaskItem:
Set olSession = Application.Session
Set olSourceFolder = olSession.Folders("Old PST").Folders("Deleted Items")
Set olTargetFolder = olSession.Folders("New PST").Folders("Deleted Items")
Set olSourceItems = olSourceFolder.Items
For Each olItem in olSourceItems
Select Case True
Case TypeOf olItem Is AppointmentItem
Set olAppointmentItemSource = olItem
Set olAppointmentItemTarget = olAppointmentItemSource.Copy
olAppointmentItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is ContactItem
Set olContactItemSource = olItem
Set olContactItemTarget = olContactItemSource.Copy
olContactItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is DistListItem
Set olContactItemSource = olItem
Set olContactItemTarget = olContactItemSource.Copy
olContactItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is JournalItem
Set olJournalItemSource = olItem
Set olJournalItemTarget = olJournalItemSource.Copy
olJournalItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is MailItem
Set olMailItemSource = olItem
Set olMailItemTarget = olMailItemSource.Copy
olMailItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is MeetingItem
Set olMeetingItemSource = olItem
Set olMeetingItemTarget = olMeetingItemSource.Copy
olMeetingItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is NoteItem
Set olNoteItemSource = olItem
Set olNoteItemTarget = olNoteItemSource.Copy 'This generates the error
olNoteItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is PostItem
Set olPostItemSource = olItem
Set olPostItemTarget = olPostItemSource.Copy
olPostItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is ReportItem
Set olReportItemSource = olItem
Set olReportItemTarget = olReportItemSource.Copy
olReportItemTarget.Move olFolderTarget
Case TypeOf olObjectSource Is TaskItem
Set olTaskItemSource = olItem
Set olTaskItemTarget = olTaskItemSource.Copy 'This generates the error
olTaskItemTarget.Move olFolderTarget
End Select
Next
Я заметил, где происходит ошибка в коде выше, который я тестировал.
Почему мой код выбрасывает ошибку во время выполнения и как я могу это исправить? Другими словами, как мне имитировать c функциональность Copy to Folder
GUI, используя VBA, который будет работать со всеми типами?
Спасибо.