回复/转发/发送时如何在主题上添加特定的附件名称?

时间:2018-07-18 08:11:05

标签: vba

我是新来的,但是我对VBA和宏非常感兴趣,可以帮助我保持邮箱井井有条。 简而言之-我在翻译办公室工作,每当客户要求翻译时,我都会向他们发送我们的服务报价(报价XXXX.pdf)。

我发现以下字符串将附件名称添加到邮件主题:

Private WithEvents Mail As Outlook.MailItem
Private WithEvents Inspectors As Outlook.Inspectors

Private Sub Application_Startup()
  Set Inspectors = Application.Inspectors
End Sub

Private Sub Inspectors_NewInspector(ByVal Inspector As Inspector)
  If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
    Set Mail = Inspector.CurrentItem
  End If
End Sub

Private Sub Mail_AttachmentAdd(ByVal Attachment As Attachment)
  Mail.Subject = " / (" & Attachment.DisplayName & ")"
End Sub

但是,无论附件是什么,它仅用附件名称替换旧主题(并在附件名称中添加“ /()”)。我的邮件签名还包含一个小的图像文件,因此有时会将图像名称复制到主题行。

我有2个问题,非常感谢他们的帮助:

  1. 如何使它添加附件名称,而不是替换旧主题,使它看起来像
  

旧主题文字/(引用XXXX.pdf)

  1. 如何使此宏仅适用于引号(仅当附件包含“ Quote”时才将附件名称添加到主题)?

非常感谢!

1 个答案:

答案 0 :(得分:0)

对不起,看来我自己找到了解决方案。这是更新的脚本:

Private WithEvents Mail As Outlook.MailItem 
Private WithEvents Inspectors As Outlook.Inspectors

Private Sub Application_Startup()   
Set Inspectors = Application.Inspectors 
End Sub

Private Sub Inspectors_NewInspector(ByVal Inspector As Inspector)   
  If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
    Set Mail = Inspector.CurrentItem   
  End If 
End Sub

Private Sub Mail_AttachmentAdd(ByVal Attachment As Attachment)   
  If Attachment.DisplayName Like "*Quote*" Then
    Mail.Subject = Mail.Subject & " / " & Attachment.DisplayName   
  End If 
End Sub