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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15791688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:23:15  来源:igfitidea点击:

User-defined type not defined - Using VBA to Import Pictures to Contacts in Outlook 2010

vbaoutlook-2010

提问by Susan T.

I'm trying to use some VBA in Outlook 2010 to bring in pictures for a contact list. When I last tried this in Outlook 2007, it worked fine. But now, I've been upgraded to Outlook 2010, and it no longer works. It errors on the Dim rec as ADODB.record set line and gives a Compile Error: User-defined type not defined.

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

Any ideas what I need to change to get this to work in Outlook 2010?

任何想法我需要改变什么才能让它在 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

采纳答案by SeanC

In the code editor, you need to add the reference to the ADODB library.

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

Go to the Tools -> Referencesmenu
access menu

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

and search for the Microsoft ActiveX Data Objectsx.x Library- Note that the version number will change depending on which version is loaded on your machine

并搜索Microsoft ActiveX Data Objectsxx Library- 请注意,版本号将根据您机器上加载的版本而变化

references

references