ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 5663|回复: 4

!!紧急求助!!-关于修改保存好邮件的标题及文件名。

[复制链接]

TA的精华主题

TA的得分主题

发表于 2008-12-1 11:58 | 显示全部楼层 |阅读模式
老板刚刚安排我一个工作,把outlook导出邮件更改格式保存。具体的要求是:在邮件标题前加入日期发送的日期,格式为:"yymmdd - ",并且要把这份邮件的文件名前面也插入日期:格式为"yymmdd - ".
如:请看附件。
更改前,邮件的标题为"this is a test",邮件的文件名也是"this is a test".
更改后,邮件的标题为"081201 - this is a test" 邮件的文件名也改为"081201 - this is a test"

我这儿有一堆上千封邮件,求各位达人帮忙!

Sample1.rar

10.58 KB, 下载次数: 10

TA的精华主题

TA的得分主题

 楼主| 发表于 2008-12-1 13:58 | 显示全部楼层
各位老大们,帮帮忙啊。我要哭了。。。书到用时方恨少!

TA的精华主题

TA的得分主题

 楼主| 发表于 2008-12-2 13:03 | 显示全部楼层
求人不如求已。搞了个半自动的。依次打开每个文件,运行代码。修改后文件的保存路径可自行修改,此例为"d:\test\"。
Sub save_mail()

    'Declaration
    Dim myItems, myItem As Object
    Dim myOrt As String
    Dim myOlApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Dim myOlSel As Object
    'Ask for destination folder
    myOrt = "d:\test\"
   
   
    'work on selected items
    Set myOlExp = myOlApp.ActiveExplorer
    Set myItem = Outlook.ActiveInspector.CurrentItem

    'Create filename
  
    strdate = myItem.SentOn
    newdate = Format(strdate, "yymmdd")
    myItem.Subject = newdate & " - " & myItem.Subject
    strSub = CleanFileName(myItem.Subject)
    strname = strSub & ".msg"
    'Save file
    myItem.SaveAs myOrt & strname
    myItem.Close olSave
  
   
'free variables
    Set myItems = Nothing
    Set myItem = Nothing
    Set myOlApp = Nothing
    Set myOlExp = Nothing
    Set myOlSel = Nothing
   
End Sub
Function CleanFileName(strText As String) As String
    Dim strStripChars As String
    Dim intLen As Integer
    Dim i As Integer
    strStripChars = "/\[]:=," & Chr(34)
    intLen = Len(strStripChars)
    strText = Trim(strText)
    For i = 1 To intLen
        strText = Replace(strText, Mid(strStripChars, i, 1), "")
    Next
    CleanFileName = strText
End Function

TA的精华主题

TA的得分主题

发表于 2008-12-6 22:12 | 显示全部楼层
参考一下本帖置顶的VBA集中营。下面的帖子实际上就很容易改造成你所需要的功能。
http://club.excelhome.net/viewthread.php?tid=252928&px=0

以下代码请参考。我测试过,在XP+OUTLOOK2007下运行正常。
Sub Savethemail()
    Dim olApp As New Outlook.Application
    Dim nmsName As Outlook.NameSpace
    Dim fldFolder As Outlook.Folder
    Dim vItem As Object
    Set nmsName = olApp.GetNamespace("MAPI")
    Set fldFolder = nmsName.GetDefaultFolder(olFolderInbox)
    If fldFolder.Items.count > 0 Then
        For Each vItem In fldFolder.Items
           strname = vItem.Subject '
           strname = Replace(strname, "*", "_") '
           strname = Replace(strname, "\", "_") '
           strname = Replace(strname, "/", "_") '
           strname = Replace(strname, "$", "_") '
           strname = Replace(strname, "%", "_") '
           strname = Replace(strname, "!", "_") '
           strname = Replace(strname, "~", "_") '
           strname = Replace(strname, "(", "_") '
           strname = Replace(strname, ")", "_") '
           strname = Replace(strname, "+", "_") '
           strname = Replace(strname, ":", "_") '
           strdate = Format(vItem.SentOn, "yymmdd")
           vItem.SaveAs "C:\OLtemp\" & strdate & " - " & strname & ".txt", olTXT '
        Next
    End If
    Set fldFolder = Nothing
    Set nmsName = Nothing
End Sub

TA的精华主题

TA的得分主题

发表于 2019-11-8 10:31 | 显示全部楼层
aaaaabbbbb 发表于 2008-12-6 22:12
参考一下本帖置顶的VBA集中营。下面的帖子实际上就很容易改造成你所需要的功能。
http://club.excelhome.n ...

你好,运行时老是提示strdate = Format(vItem.SentOn, "yymmdd") 对象不支持该属性和方法,这是怎么回事呢?
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-25 19:27 , Processed in 0.031295 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表