2011-12-02 47 views
-1

我想創建一個自動郵件響應,當我按下宏按鈕時,該郵件當前處於活動狀態。自動電子郵件的Outlook中的宏

應從外部文件讀取自動電子郵件正文 - 格式爲.txt

目的:當我按下一個宏按鈕時,它會讀取該文件的內容,並給出活動郵件的自動回覆。

這是可能與宏或VBA?

+0

借調。 0接受7個問題意味着你沒有正確參與社區。 – brettdj

回答

0

只是所以我理解你通過所有主動/啓用電子郵件迭代它的內容,然後發送文本文件或文本文件中的內容作爲附件。

這是顯示如何閱讀文本文件的鏈接。

嘿,拿來看的鏈接VBA read text files

看看是否有所幫助。

+0

不是我的目的是當我按下那個宏密鑰 –

+0

好了,從文本文件中讀取郵件的包含併發送郵件給客戶端。您想要創建一個宏按鈕,用於讀取文本文件的信息,然後將其作爲對當前正在查看的郵件客戶端或郵件消息的回覆。試試這個http://www.answermysearches.com/how-to-send-an-outlook-email-with-vba-macros/340/ – Postonoh

+0

http://www.everythingaccess.com/tutorials.asp?ID= Outlook-Send-E-mail-Without-Security-Warning此外。 – Postonoh

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 
+0

感謝它的工作正常 –

相關問題