将特定文件类型另存为带有接收日期时间的附件 [英] Save specific file type as attachment with received date time

查看:72
本文介绍了将特定文件类型另存为带有接收日期时间的附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 仅将图像保存到文件夹,即.jpg .jpeg .gif .png
  2. 包括接收日期
  3. 将所有保存的图像文件类型重命名为".jpg"

我大部分都失望了.它正在保存这样的文件:test.jpeg.jpg和test.jpg.jpg

I have most of it down. It is saving files like this: test.jpeg.jpg and test.jpg.jpg

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    Dim dateFormat As String
    Dim strFileExtension As String

    saveFolder = "C:\emails\"
    dateFormat = Format(itm.ReceivedTime, "yyyy-mm-dd Hmm ")
    strFileExtension = ".jpg"

    For Each objAtt In itm.Attachments
        objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName & strFileExtension
        Set objAtt = Nothing
    Next
End Sub

推荐答案

类似以下的方法将起作用:

Something like the following would work:

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    Dim dateFormat As String
    Dim strFileExtension As String
    Dim strSaveFileName as string

    saveFolder = "C:\emails\"
    dateFormat = Format(itm.ReceivedTime, "yyyy-mm-dd Hmm ")
    strFileExtension = ".jpg"

    For Each objAtt In itm.Attachments
        if lcase(right(objAtt.FileName, 4)) = "jpeg" or lcase(right(obtAtt.FileName, 3) = "jpg") then

            strSaveFileName = mid(objAtt.FileName, instr(1, objAtt.FileName, ".", length(objAtt.FileName) - instr(1, obtAtt.FileName)) & strFileExtension
            objAtt.SaveAsFile saveFolder & "\" & dateFormat & strSaveFileName
            Set objAtt = Nothing
        End if
    Next
End Sub

这具有添加的 if 语句,以测试文件扩展名是JPG还是JPEG.如果是,那么它将使用一些字符串函数来获取扩展名之前的文件名,并在最终的 saveasfile 中使用该文件名.

This has an added if statement to test for the file extension being JPG or JPEG. If it is, then it uses some string functions to grab the bits of the filename before the extension and uses that in the final saveasfile.

这篇关于将特定文件类型另存为带有接收日期时间的附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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