如何使用VBA将电子邮件导出到Access [英] How do export e-mail messages to Access using VBA

查看:83
本文介绍了如何使用VBA将电子邮件导出到Access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VBA将电子邮件自动导出到Access。我在techrepublic.com上找到了一个看起来像答案的代码,但由于我不熟悉VBA,我遇到了问题。代码如下: 

I'm trying to have emails be automatically exported to Access using a VBA. I found a code on techrepublic.com that looks like the answer, but since I am not familiar with VBA's I'm running into issues. The code is this: 

Sub ExportMailByFolder()

Sub ExportMailByFolder()

     '从每封邮件中导出指定字段

     'Export specified fields from each mail

     '所选文件夹中的项目。

     'item in selected folder.

    Dim ns As Outlook.NameSpace

    Dim ns As Outlook.NameSpace

    Dim objFolder As Outlook.MAPIFolder

    Dim objFolder As Outlook.MAPIFolder

   设置ns = GetNamespace(" MAPI")

    Set ns = GetNamespace("MAPI")

   设置objFolder = ns.PickFolder

    Set objFolder = ns.PickFolder

    Dim adoConn As ADODB.Connection

    Dim adoConn As ADODB.Connection

    DOD adoRS As ADODB.Recordset

    Dim adoRS As ADODB.Recordset

    Dim intCounter As Integer

    Dim intCounter As Integer

   设置adoConn = CreateObject(" ADODB.Connection")

    Set adoConn = CreateObject("ADODB.Connection")

   设置adoRS = CreateObject(" ADODB.Recordset")

    Set adoRS = CreateObject("ADODB.Recordset")

     'DSN和目标文件必须存在。

     'DSN and target file must exist.

    adoConn.Open"DSN = OutlookData;"

    adoConn.Open "DSN=OutlookData;"

    adoRS.Open"SELECT * FROM email",adoConn,_

    adoRS.Open "SELECT * FROM email", adoConn, _

    adOpenDynamic,adLockOptimistic

    adOpenDynamic, adLockOptimistic

     '循环选择所选文件夹。

     'Cycle through selected folder.

   对于intCounter = objFolder.Items.Count到1步-1

    For intCounter = objFolder.Items.Count To 1 Step -1

       使用objFolder.Items(intCounter)

        With objFolder.Items(intCounter)

             '将属性值复制到相应的字段

             'Copy property value to corresponding fields

             '在目标文件中。

             'in target file.

            如果。类= olMail然后

            If .Class = olMail Then

          &NBSP ;     adoRS.AddNew

                adoRS.AddNew

                ADORS(QUOT受试者QUOT)= .Subject

                adoRS("Subject") = .Subject

              &NBSP ; ADORS(QUOT;机体")=。体

                adoRS("Body") = .Body

              &NBSP ; ADORS(QUOT; FROMNAME")= .SenderName

                adoRS("FromName") = .SenderName

              &NBSP ; ADORS(QUOT; ToName")=。为了

                adoRS("ToName") = .To

              &NBSP ; ADORS(QUOT; FROMADDRESS")= .SenderEmailAddress

                adoRS("FromAddress") = .SenderEmailAddress

              &NBSP ; ADORS(QUOT; FromType")= .SenderEmailType

                adoRS("FromType") = .SenderEmailType

              &NBSP ; ADORS(QUOT; CCName")= .CC

                adoRS("CCName") = .CC

              &NBSP ; ADORS(QUOT; BCCName")= .BCC

                adoRS("BCCName") = .BCC

              &NBSP ; ADORS(QUOT;重要性及QUOT)= .Importance

                adoRS("Importance") = .Importance

              &NBSP ; ADORS(QUOT;灵敏度")= .Sensitivity

                adoRS("Sensitivity") = .Sensitivity

              &NBSP ; ADORS(QUOT;附件")= .Attachment

                adoRS("Attachments") = .Attachment

              &NBSP ; adoRS.Update

                adoRS.Update

           结束如果

            End If

       结束

        End With

   下一步

    Next

    adoRS.Close

    adoRS.Close

   设置adoRS = Nothing

    Set adoRS = Nothing

   设置adoConn = Nothing

    Set adoConn = Nothing

   设置ns = Nothing

    Set ns = Nothing

   设置objFolder = Nothing

    Set objFolder = Nothing

End Sub

我在哪里获得此链接:http://www.techrepublic.com/blog/ how-do-i / how-do-i-export-e-mail-messages-to-access-using-vba /

The link for where I got this is here: http://www.techrepublic.com/blog/how-do-i/how-do-i-export-e-mail-messages-to-access-using-vba/

我只是到了我所在的地步Visual Basic for Applications,我去了Insert并选择了Module。然后我复制并粘贴了上面列出的代码。然后我尝试运行它,但出现了一个错误,上面写着"编译错误:用户定义的类型
未定义。"我试着完全按照说明操作。令我困惑的最大问题是,它说运行向导,我不知道该怎么做。如果有人可以查看说明和代码,然后将其愚蠢到我理解的地方
并且可以让它工作,这将是惊人的。

I have only gotten to the point where I am in Visual Basic for Applications, I went to Insert and selected Module. I then copied and pasted the code listed above. I then tried to run it, but an error comes up that says "Compile Error: User-Defined type not defined." I tried following the instructions exactly. The biggest thing that confuses me is that it says to run the wizard and i have no idea how to do that. If someone could review the instructions and code and then dumbify it down to where I understand and can get it to work that would be amazing.

我正在尝试在我的个人计算机上执行此操作,然后再在我的工作计算机上执行此操作。我这样做是因为我与其他两位同事一起分享了一封内部电子邮件,其中一位同事坚持要我们打印每封电子邮件和我们的回复,引用
,然后归档。这太荒谬了,占用了时间,资源和空间。我试过告诉他一切都归档但是他拒绝听。所以我想如果我中途遇到他并将我们的电子邮件自动保存在他可以轻松访问的
文件中,那么它将减少时间,资源和空间。请帮助。 

I'm trying to do it on my personal computer before doing it on my work computer. I'm doing this because I share an internal email at work with 2 other coworkers and one of the coworkers insists that we print each and every email and our responses, reference them, and then file them. It's ridiculous and it's taking up time, resources, and space. I've tried telling him that everything gets archived but he refuses to listen. So I figure if I meet him halfway and have our emails automatically saved in a file that he can easily access then it will shave down on time, resources, and space. Please help. 

推荐答案

您好,

>>编译错误:用户 - 未定义的定义类型

>>Compile Error: User-Defined type not defined

单击"确定"后,将选择哪一行?我认为它可能会突出显示"Dim adoConn As ADODB.Connection"。如果是,请检查是否添加了参考Microsoft ActiveX Data Objects x.x Library。

After clicking Ok, which line would be selected? I think it may highlight "Dim adoConn As ADODB.Connection". If it does, please check if you add reference Microsoft ActiveX Data Objects x.x Library.

在VBE中,请点击工具 - >引用..然后检查Microsoft ActiveX数据对象< 6.1库。

In the VBE, please click Tools -> References.. and then check Microsoft ActiveX Data Objects 6.1 Library.

此外,请按照您找到的链接中的其他步骤操作。当您使用此DSN连接数据库时,应创建DSN文件。

Besides, please follow the other steps in the link you found. The DSN file should be created as you are connecting the db using this DSN.

问候,

Celeste


这篇关于如何使用VBA将电子邮件导出到Access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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