为什么要为每个工作簿创建两封电子邮件?

时间:2019-02-18 16:29:53

标签: vba

我要从一个主工作簿中提取一个工作表,并为每个工作簿创建一个单独的工作簿 然后,将这些工作簿保存到文件夹中,然后将每个工作簿添加到电子邮件中。 每个工作簿都在创建2封电子邮件,但是从代码中我看不到为什么?

Sub MoveandSaveWorkBooks()


Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim wK As Worksheet

For Each wK In ThisWorkbook.Worksheets
    If wK.name = "Master Data" Then
    ElseIf wK.name = "Button" Then
    Else
    wK.Copy

    Selection.RowHeight = 84.75
    Cells.EntireColumn.AutoFit
    ActiveWorkbook.Password = UserInput
    ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & wK.name & ".xlsx"


    Dim OlApp As Object
    Dim NewMail As Object

    Set OlApp = CreateObject("Outlook.Application")
    Set NewMail = OlApp.CreateItem(0)

    On Error Resume Next
    With NewMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = ""
        .Body = "" 



    .Attachments.Add ActiveWorkbook.FullName
    .display   


    End With
    On Error GoTo 0

    Set NewMail = Nothing
    Set OlApp = Nothing

    ActiveWorkbook.Close True


End If
Next wK

Application.DisplayAlerts = True
Application.ScreenUpdating = True

0 个答案:

没有答案