导入outlook数据文件_将文档导入Outlook

导入outlook数据文件

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files to Outlook is pretty simple.  Paul and I exchanged a few more tweets and from them I learned that he has the following requirements for this process:

今天,当我回应Paul Devereux(@pdevereux)的推文时问我:“有人知道如何自动将磁盘中的文件添加到#outlook的文件夹中吗?”。 我回复并告诉Paul,使用自动化(在这种情况下为脚本)将文件添加到Outlook非常简单。 保罗和我交换了几条推文,从中我得知他对此过程有以下要求:

    * Read the file names from a DB table.

*从数据库表中读取文件名。

    * The DB could be MS Access or SQL Server.

*该数据库可以是MS Access或SQL Server。

    * Files could be of any type.

*文件可以是任何类型。

    * Needs to work with Outlook 2003, 2007, and 2010.

*需要使用Outlook 2003、2007和2010。

    * The process needs to run from outside of Outlook.

*该过程需要从Outlook外部运行。

The code for handling this is below. It’s pretty simple and I added a number of comments to help both you and Paul figure out what it’s doing.  The script uses Microsoft’s ADODB technology to connect to and read a table in the DB.  For each row in the table the script creates an Outlook DocumentItem object, a file within an Outlook folder, fills in some information about it, and saves it into an Outlook folder.  In this case I used the inbox, but Paul can modify the code to save it into the folder of his choice.  Paul will also need to set the ADODB connection string to connect to his database.  He can use Connectionstrings.com to find the correct string for either Access or SQL Server.  Finally, he will also need to edit the field names to match those that appear in his table.

处理此的代码如下。 这非常简单,我添加了许多评论来帮助您和Paul找出正在执行的操作。 该脚本使用Microsoft的ADODB技术连接并读取数据库中的表。 脚本为表中的每一行创建一个Outlook DocumentItem对象(一个Outlook文件夹中的文件),填写有关它的一些信息,然后将其保存到Outlook文件夹中。 在这种情况下,我使用了收件箱,但是Paul可以修改代码以将其保存到他选择的文件夹中。 Paul还需要设置ADODB连接字符串以连接到他的数据库。 他可以使用Connectionstrings.com查找Access或SQL Server的正确字符串。 最后,他还需要编辑字段名称以匹配表中显示的名称。

The code is written in VBScript making it easy for Paul to edit and use.  All he has to do is copy and paste the code into Notepad, edit it (I included comments where things can or need to change), and save it with a .vbs extension.  He can run it by double-clicking the saved .vbs file.

该代码使用VBScript编写,使Paul易于编辑和使用。 他所需要做的就是将代码复制并粘贴到记事本中,对其进行编辑(我在其中可以更改或需要更改的地方添加了注释),然后使用.vbs扩展名保存。 他可以通过双击保存的.vbs文件来运行它。

Since I don’t have Paul’s database and therefore don’t know what fields it contains or the names of those fields I couldn’t test the code before posting.  It may contain errors and there might be some debugging required to get it fully operational.  That aside, it should be pretty close to what Paul needs to solve his problem.  Hopefully he’ll find it useful.

由于我没有Paul的数据库,因此不知道数据库包含哪些字段或这些字段的名称,因此我无法在发布前测试代码。 它可能包含错误,并且可能需要进行一些调试才能使其完全运行。 除此之外,它应该非常接近保罗解决他的问题所需要的。 希望他会发现它有用。

'Create constants
Const olFolderInbox = 6
'Create variables
Dim olkApp, olkSes, olkFld, olkDoc, adoCon, adoRec, strFileType

'Connect to Outlook
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
'Change the default profile name on the next line as needed
olkSes.Logon "Outlook"
'Change the folder as needed
Set olkFld = olkSes.GetDefaultFolder(olFolderInbox)

'Connect to the database table
Set adoCon = CreateObject("ADODB.Connection")
'Edit the connection string on the next line.
adoCon.Open "Connection_String_Goes_Here"
'Edit the SQL statement on the next line as needed
Set adoRec = adoCon.Execute("SELECT * FROM Table_Name")

'Process the records
With adoRec
    Do Until .EOF
        Set olkDoc = olkFld.Items.Add("IPM.Document")
        'Edit the field name on the next line
        olkDoc.Attachments.Add .Fields("Name_of_File_Path_Field")
        'Edit the field name on the next line
        olkDoc.Subject = .Fields("Name_of_File_Name_Field")
        'Edit the field names on the next line
        strFileType = Mid(.Fields("Name_of_File_Name_Field"), InStrRev(.Fields("Name_of_File_Name_Field"), ".") + 1)
        'Add more file types as needed
        Select Case LCase(strFileType)
            Case "doc"
                olkDoc.MessageClass = "IPM.Document.Word.Document.8"
            Case "docx"
                olkDoc.MessageClass = "IPM.Document.Word.Document.12"
            Case "pdf"
                olkDoc.MessageClass = "IPM.Document.AcroExch.Document"
            Case "ppt"
                olkDoc.MessageClass = "IPM.Document.PwerPoint.Show.8"
            Case "pptx"
                olkDoc.MessageClass = "IPM.Document.PwerPoint.Show.12"
            Case "txt"
                olkDoc.MessageClass = "IPM.Document.txtfile"
            Case "xlsm"
                olkDoc.MessageClass = "IPM.Document.Excel.SheetMacroEnabled.12"
            Case "xls"
                olkDoc.MessageClass = "IPM.Document.Excel.Sheet.8"
            Case "xlsx"
                olkDoc.MessageClass = "IPM.Document.Excel.Sheet.12"
            Case "zip"
                olkDoc.MessageClass = "IPM.Document.WinZip"
        End Select
        olkDoc.Save
        .MoveNext
    Loop
End With

'Clean up
adoRec.Close
adoCon.Close
olkSes.Logoff
Set adoRec = Nothing
Set adoCon = Nothing
Set olkDoc = Nothing
Set olkFld = Nothing
Set olkSes = Nothing
Set olkApp = Nothing
msgbox "Import complete.", vbInformation + vbOKOnly, "Import Files to Outlook"
WScript.Quit

Note: This is a repost of a posting I created on my external blog. And while I say "I hope he [paul] finds it useful", what I really mean is, I hope you too can find it helpful :)

注意:这是我在外部博客上创建的帖子的转发。 虽然我说“我希望他(保罗)觉得有用”,但我真正的意思是,我希望您也能找到帮助:)

When trying it for yourself, start small, in easy to identify steps and always double check before you begin.

自己尝试时,请从小处着手,以易于识别的步骤开始,并始终在开始之前仔细检查。

Any comments or issues, please post a comment below and we will try to address them.

任何意见或问题,请在下面发表评论,我们将尽力解决。

翻译自: https://www.experts-exchange.com/articles/3429/Importing-Documents-Into-Outlook.html

导入outlook数据文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值