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