用户定义的类型未定义 - 使用VBA将图片导入Outlook 2010中的联系人

时间:2013-04-03 15:32:08

标签: vba outlook-2010

我正在尝试在Outlook 2010中使用一些VBA来为联系人列表引入图片。当我上次在Outlook 2007中尝试此操作时,它运行正常。但是现在,我已经升级到Outlook 2010,它不再有效。它在Dim上的错误记录为ADODB.record设置行,并给出编译错误:未定义的用户定义类型。

我需要改变什么才能让它在Outlook 2010中运行?

Public Sub UpdateContactPhoto()

Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")

Set myContacts = myNamespace.Folders.Item("Mailbox - Thomas, Susan"). _
                 Folders.Item("Temp Contacts").Items

Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
For Each myItem In myContacts
    If (myItem.Class = olContact) Then
        Dim myContact As Outlook.ContactItem
        Set myContact = myItem
        Dim strPhoto As String

        Dim rec As ADODB.Recordset
        Dim strSQL As String

        strSQL = "SELECT abcdefg from 123456 Where FullName = '" & myItem & "'"

        Set con = New ADODB.Connection
        con.Open = "Provider=SQLOLEDB;Data Source=ABC;Initial Catalog=XYZ;User ID=867;Password=5309;"
        Set rec = con.Execute(strSQL)

        If Not rec.EOF Then
            TheValue = rec.Fields(3).Value
            strPhoto = "\\picserver\EmployeePics\" & TheValue

            If fs.FileExists(strPhoto) Then
                myContact.AddPicture strPhoto
                myContact.Save
            End If
        End If
    Else

    End If
Next

End Sub

1 个答案:

答案 0 :(得分:0)

在代码编辑器中,您需要添加对ADODB库的引用。

转到工具 - >参考文献菜单
access menu

并搜索 Microsoft ActiveX数据对象 x.x - 请注意版本号将根据计算机上加载的版本而更改

references