0
我想在運行宏下面運行,它給了我錯誤「對象變量或塊變量未設置」。對象變量或在運行宏時沒有設置塊變量
我的代碼:
Dim i As Long
Public WithEvents olInboxItems As Items
Public Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
Set olInboxItems = GetFolderPath("Fulfilment.qatar\Inbox\Team Helpdesk May 2016").Items
Set objNS = Nothing
End Sub
Public Sub olInboxItems_ItemAdd(ByVal Item As Object)
Dim strCat As String
If Item.Class = olMail Then
Select Case i
Case 0
strCat = "Case 0"
Case 1
strCat = "Case 1"
Case 2
strCat = "Case 2"
Case 3
strCat = "Case 3"
Case 4
strCat = "Case 4"
End Select
Item.Categories = strCat
Item.Save
Err.Clear
End If
i = i + 1
Debug.Print i
If i = 5 Then i = 0
End Sub
' Use the GetFolderPath function to find a folder in non-default mailboxes
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
埃羅91下面的代碼: – user2646207
公用Sub Application_Startup() 昏暗objNS作爲命名空間 設置objNS = Application.Session 設置olInboxItems = GetFolderPath( 「Fulfilment.qatar \收件箱\團隊服務檯2016年5月」)的項目 設置。 objNS = Nothing End Sub – user2646207