Обычно вы должны использовать следующую конструкцию:
If obj Is Nothing Then
' need to initialize obj: '
Set obj = ...
Else
' obj already set / initialized. '
End If
Итак, используйте вместо этого следующий код:
Sub MoveItems()
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
Dim myitems As Outlook.Items
Dim myitem As Object
Dim objApp As Outlook.Application
Dim objFolder As Outlook.Folder
Dim objTestFolder As Outlook.Folder
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
On Error Resume Next
Set objTestFolder = myInbox.Folders("test")
If objTestFolder Is Nothing Then
Set myDestFolder = myInbox.Folders.Add("test", Outlook.OlDefaultFolders.olFolderInbox)
End If
On Error GoTo 0
Set oDeletedItems = Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set myitems = oDeletedItems.Items
Debug.Print myitems.Count
For I = myitems.Count To 1 Step -1
myitems.Item(I).Move myDestFolder
Next
End Sub