0

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

任何想法我需要更改才能使其在 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
4

1 回答 1

0

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

转到工具 -> 参考菜单
访问菜单

并搜索Microsoft ActiveX 数据对象xx- 请注意,版本号将根据您机器上加载的版本而改变

参考

于 2013-04-03T16:12:09.903 回答