VBA无法识别MAPI [英] VBA not Recognizing MAPI

查看:263
本文介绍了VBA无法识别MAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VBA进入Outlook文件夹并将消息正文放入单元格中.但是在

I'm using VBA to enter into an outlook folder and put the message body into a cell. However on

 set ns = getnamespace("MAPI")

我收到一个错误未注册自动化错误库".我选择了以下与Outlook相关的参考(在Excel中):

I get an error "automation error library not registered". I have the following outlook related references selected (within Excel):

  • Outlook 14.0对象库,
  • Outlook SharePoint Social Provider,
  • Outlook Social Provider的可扩展性,
  • Outlook视图控件

我正在使用Excel2010.整个代码如下.任何帮助将不胜感激.

I'm using Excel 2010. The entire code follows. Any help would be greatly appreciated.

Dim ns As Namespace
Dim inbox As Mapifolder
Dim item As Object
Dim atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim SubFolder As Mapifolder
Dim SubSubFolder As Mapifolder
Dim VariableName As Name
Dim Working As Workbook
Dim Sheet As Worksheet


Set ns = getnamespace("MAPI")
Set inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = inbox.Folders("xx") 
Set SubSubFolder = SubFolder.Folders("xxxx")
Set Working = ThisWorkbook
Set Sheet = Working.Worksheets("Sheet1")

If SubSubFolder.Items.Count > 0 Then

 For Each item In SubSubFolder.Items
Sheet.Range("A1") = item.Body
Next item

End If

推荐答案

Namespace()在Outlook VBA中将有效,因为存在一个指向Outlook.Application对象的固有Application变量,并且该变量是全局变量.即,无需指定"Application.*"即可使用其所有属性和方法

Namespace() will be valid in Outlook VBA since there is an intrinsic Application variable that points to the Outlook.Application object and the variable is global. i.e. all of its properties and methods are available without specifying "Application.*"

对于Excel VBA,Application指向Excel.Application对象的实例,因此您必须显式创建和初始化Outlook.Application对象:

In case of Excel VBA, Application points to an instance of the Excel.Application object, so you must explicitly create and initialize the Outlook.Application object:

set olApp = CreateObject("Outlook.Application")
Set ns = olApp.getnamespace("MAPI")
...

这篇关于VBA无法识别MAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆