首页 文章

附件嵌入

提问于
浏览
0

我有一个Excel宏用于发送带有Excel工作簿附件的电子邮件 . 有时,它不是附加文件,而是成为嵌入对象 . 该嵌入式对象可由公司内的用户打开(在点击“您即将激活可能包含病毒或对您的计算机有害的嵌入式对象”之后 . 确保它来自可信赖的来源非常重要 . 你想继续吗?“),但对于公司以外的人来说,电子邮件似乎根本没有附件 .

这似乎是随机发生的,并且仅在某些计算机上发生 . 因此,如果列表包含15个电子邮件列表和附件,则会发生在0到15个电子邮件之间的任何位置 . 为了清楚起见,我的目标是发送带有常规附件的电子邮件 . 运行Excel 2003,Outlook 2003和Windows XP .

Sub Email()  
Dim P As String  
Dim N As String  
Dim M As String  
Dim Subject As String  
Dim Addresses As String  
Dim olApp As Outlook.Application  
Dim olNewMail As Outlook.MailItem  

Application.DisplayAlerts = False  

M = ActiveWorkbook.Name  

For c = 2 To 64000  
    If Range("B" & c) = "" Then Exit For  
    If UCase(Range("E" & c)) = "Y" Then  
        Workbooks(M).Sheets("Main").Activate  
        Subject = Range("A" & c)  
        Addresses = Range("B" & c)  
        P = Range("C" & c)  
        N = Range("D" & c)  
        If Right(P, 1) <> "\" Then P = P & "\"  
        If Right(N, 4) <> ".xls" Then N = N & ".xls"  
        Set olApp = New Outlook.Application  
        Set olNewMail = olApp.CreateItem(olMailItem)  
        With olNewMail  
            .Display  
            .Recipients.Add Addresses  
            Application.Wait (Now + TimeValue("0:00:01"))  
            SendKeys ("{TAB}")  
            .Subject = Subject  
            .Attachments.Add P + N  
            .Send  
        End With  
        Set olNewMail = Nothing  
        Set olApp = Nothing  

    End If  
Next c  

Range("E2:E65536").ClearContents  
Application.DisplayAlerts = True  

End Sub

1 回答

相关问题