Outlook应用程序中的VB错误 [英] VB error in Outlook application
本文介绍了Outlook应用程序中的VB错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写以下代码,将邮件保存到收件箱子文件夹(存档):
Sub MoveOldEmail()
Dim oItem As MailItem
Dim objMoveFolder As MAPIFolder
Dim objInboxFolder As MAPIFolder
Dim i As 整数
设置 objMoveFolder = GetFolder(" )
设置 objInboxFolder = GetNamespace(" ).GetDefaultFolder(olFolderInbox)
对于我= objInboxFolder.Items.Count- 1 >要 0 步骤 -1
使用 objInboxFolder.Items(i)
' '当不支持.receivedtime时,返回错误438
打开 错误 恢复 如果 .ReceivedTime< DateAdd(" ,-24,现在)然后
如果 Err.Number = 0 然后
.Move objMoveFolder
其他
错误清除
结束 如果
结束 如果
结束 使用
下一步
设置 objMoveFolder = 什么都没有
设置 objInboxFolder = 什么都没有
结束 子
公共 功能 GetFolder(strFolderPath As 字符串) As MAPIFolder
' 'strFolderPath需要类似于
' '公共文件夹\所有公共文件夹\公司\销售"或
' '个人文件夹\收件箱\我的文件夹"
Dim objNS As NameSpace
暗 colFolders As 文件夹
Dim objFolder As MAPIFolder
Dim arrFolders() As 字符串
暗 i As 长
打开 错误 转到 TrapError
strFolderPath = Replace(strFolderPath," ," \")
arrFolders()= Split(strFolderPath," )
设置 objNS = GetNamespace(" )
打开 错误 恢复 设置 objFolder = objNS.Folders.Item(arrFolders( 0 ))
如果 不是 objFolder 是 没事 然后
对于,我= 1 到 UBound(arrFolders )
设置 colFolders = objFolder.Folders
设置 objFolder = 什么都没有
设置 objFolder = colFolders.Item(arrFolders(i))
如果 objFolder 是 没什么 然后
退出 用于
结束 如果
下一步
结束 如果
打开 错误 转到 TrapError
设置 GetFolder = objFolder
设置 colFolders = 什么都没有
设置 objNS = 什么都没有
Exit_Proc:
退出 功能
TrapError:
MsgBox错误号& " &错误说明
结束 功能
但是出现以下错误:
Error 1 Name ''GetNamespace'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 17 26 WindowsApplication1 Error 2 Name ''olFolderInbox'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 17 64 WindowsApplication1 Error 3 Number of indices is less than the number of dimensions of the indexed array. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 56 19 WindowsApplication1 Error 4 Name ''GetNamespace'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 58 17 WindowsApplication1
请告诉我如何恢复它...:doh::doh:
解决方案
确保您的项目中包含正确的命名空间.
错误1& 4未声明名称"GetNamespace". D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 17 26 WindowsApplication1
非常正确!此方法在Outlook对象中公开.您尝试使用它的方式看起来像是普通的页面方法.创建Outlook对象,然后尝试.
错误2名称'olFolderInbox'未声明. D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 17 64 WindowsApplication1
我没有定义它们.它们是在Outlook中用于查找项目的固定整数.
请参阅本文 [Sub MoveOldEmail() Dim oItem As MailItem Dim objMoveFolder As MAPIFolder Dim objInboxFolder As MAPIFolder Dim i As Integer Set objMoveFolder = GetFolder("Personal Folders\Inbox\Archive") Set objInboxFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox) For i = objInboxFolder.Items.Count - 1 To 0 Step -1 With objInboxFolder.Items(i) ''Error 438 is returned when .receivedtime is not supported On Error Resume Next If .ReceivedTime < DateAdd("h", -24, Now) Then If Err.Number = 0 Then .Move objMoveFolder Else Err.Clear End If End If End With Next Set objMoveFolder = Nothing Set objInboxFolder = Nothing End Sub Public Function GetFolder(strFolderPath As String) As MAPIFolder '' strFolderPath needs to be something like '' "Public Folders\All Public Folders\Company\Sales" or '' "Personal Folders\Inbox\My Folder" Dim objNS As NameSpace Dim colFolders As Folders Dim objFolder As MAPIFolder Dim arrFolders() As String Dim i As Long On Error GoTo TrapError strFolderPath = Replace(strFolderPath, "/", "\") arrFolders() = Split(strFolderPath, "\") Set objNS = GetNamespace("MAPI") On Error Resume Next Set objFolder = objNS.Folders.Item(arrFolders(0)) If Not objFolder Is Nothing Then For i = 1 To UBound(arrFolders) Set colFolders = objFolder.Folders Set objFolder = Nothing Set objFolder = colFolders.Item(arrFolders(i)) If objFolder Is Nothing Then Exit For End If Next End If On Error GoTo TrapError Set GetFolder = objFolder Set colFolders = Nothing Set objNS = Nothing Exit_Proc: Exit Function TrapError: MsgBox Err.Number & " " & Err.Description End Function
But I am getting the following errors:
Error 1 Name ''GetNamespace'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 17 26 WindowsApplication1 Error 2 Name ''olFolderInbox'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 17 64 WindowsApplication1 Error 3 Number of indices is less than the number of dimensions of the indexed array. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 56 19 WindowsApplication1 Error 4 Name ''GetNamespace'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 58 17 WindowsApplication1
Please tell me how I can recover it ... :doh: :doh:解决方案Make sure you have got the right namespaces included in your project.
Error 1 & 4 Name ''GetNamespace'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 17 26 WindowsApplication1
Very correct! This method is exposed in the Outlook object. The way you are trying to use it looks like a normal page method. Create Outlook object and then try.
Error 2 Name ''olFolderInbox'' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 17 64 WindowsApplication1
I don''t find them defined. They are fixed integers that are used in Outlook to find an item.
Refer this article [^]for some reference. Though this is in client side in Javascript, but you will get the essence of what are the issues with Error 1 & 2 & 4
Error 3 Number of indices is less than the number of dimensions of the indexed array. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 56 19 WindowsApplication1
Sounds like a coding error. Just use debugger and then resolve the same.
这篇关于Outlook应用程序中的VB错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文