我想为按下宏按钮时当前处于活动状态的电子邮件创建自动邮件回复。
应从外部文件中读取自动电子邮件正文 - 格式为.txt
。
目标:当我按下宏按钮时,它会读取该.txt
文件的内容,并自动回复活动的电子邮件。
使用宏还是VBA可以实现吗?
答案 0 :(得分:2)
此过程(以及它下面的三个辅助功能)将获取当前打开或选择的电子邮件,并使用您在顶部文件路径中指定的任何文本文件内的文本回复它。
Sub ReplyCurrentMsg()
' ************************
' change this to point to the file you
' want to put in the message body
' when running the macro
' ************************
Const TEXT_FILE_PATH As String = "C:\My Files\file_to_include.txt"
Dim obj As Object
Dim msg As Outlook.mailItem
Dim msgReply As Outlook.mailItem
Dim fileNum As Integer
Dim fileContents As String
Set obj = GetCurrentItem
If TypeName(obj) = "MailItem" Then
Set msg = obj
Set msgReply = msg.Reply
fileNum = FreeFile
' http://www.exceluser.com/explore/questions/vba_textcols.htm
Open TEXT_FILE_PATH For Input As #fileNum
fileContents = Input$(LOF(fileNum), 1)
Close #fileNum
With msgReply
.Body = fileContents
.Display ' or .Send
End With
End If
End Sub
Function GetCurrentItem() As Object
Select Case True
Case IsExplorer(Application.ActiveWindow)
Set GetCurrentItem = ActiveExplorer.Selection.item(1)
Case IsInspector(Application.ActiveWindow)
Set GetCurrentItem = ActiveInspector.CurrentItem
End Select
End Function
Function IsExplorer(itm As Object) As Boolean
IsExplorer = (TypeName(itm) = "Explorer")
End Function
Function IsInspector(itm As Object) As Boolean
IsInspector = (TypeName(itm) = "Inspector")
End Function
答案 1 :(得分:0)
就这样,我了解你要迭代所有活动/启用电子邮件然后将文本文件或文本文件中的内容作为附件发送。
这是一个显示如何阅读文本文件的链接。
嘿,请看一下VBA read text files
链接看看这是否有帮助。