今天刚写的一个小程序,放到outlook中的module下 在d盘根目录中建立一个excel文件,文件包含3栏 姓名 | 时间 | 文件名 | Junny Kwong | 1/15/2007 14:41 | 艾宗文.htm |
需要包含一行数据. 具体程序如下 Sub HRI2EXCEL() '2007-1-25 '这是一个能够从活动的窗口中下载附件并将发送人,时间和附件的名称写入excel中 '运行前需要打开一封邮件,然后运行下面的代码. Dim mFileName, mSubject As String Dim iPos As Integer Dim i As Integer Dim C As MailItem Set C = ActiveInspector.CurrentItem If TypeName(C) <> "MailItem" Then MsgBox "当前活动窗口不是一封邮件" ElseIf C.Attachments.Count > 0 Then '必须是在有附件的情况下 'MsgBox C.Subject 'MsgBox C.CreationTime 'MsgBox C.SenderName Dim xlsObj As Excel.Application Set xlsObj = CreateObject("Excel.Application") xlsObj.Visible = False '用隐藏的方式执行excel xlsObj.Workbooks.Open ("D:\data.xls") For i = 1 To C.Attachments.Count xlsObj.ActiveSheet.Range("A1").Select xlsObj.Selection.End(xlDown).Select xlsObj.Selection.Offset(1, 0).Select xlsObj.Selection.Value = C.SenderName xlsObj.Selection.Offset(0, 1).Select xlsObj.Selection.Value = C.CreationTime xlsObj.Selection.Offset(0, 1).Select xlsObj.Selection.Value = C.Attachments.Item(i).FileName C.Attachments.Item(i).SaveAsFile ("D:\" & C.Attachments.Item(i).FileName) Next xlsObj.ActiveWorkbook.Save xlsObj.Quit '关闭excel窗口 Else MsgBox "当前邮件没有附件" End If End Sub
|