简体   繁体   English

Excel外观VBA 2013不适用于2016 Outlook版本

[英]Excel-outlook VBA 2013 not working on 2016 Outlook version

I'm having problems with a macro. 我在使用宏时遇到问题。 It used to work on the 2013 version of outlook and excel but for some reason the CC function has stopped working and I keep getting errors. 它曾经可以在Outlook 2013和Excel的2013版本上运行,但由于某些原因,CC功能已停止工作,并且我不断收到错误消息。

With the 2013 version I used the following code to define the CC and BCC: 在2013版本中,我使用以下代码定义CC和BCC:

Set sh = Sheets ("Sheet1")

        .to = cell.Value
        .CC = sh.Cells(cell.Row, 1).Range("C1:C1")
        .BCC = sh.Cells(cell.Row, 1).Range("D1:D1")

This however doesn't work in the 2016 version of my excel and outlook. 但是,这在我的Excel和Outlook 2016版本中不起作用。 Every single row in excel need to have its own To , CC and BCC selected from a row in Excel. excel中的每一行都需要从Excel中的一行中选择自己的To,CC和BCC。 For some reason it keeps saying CC is not a valid method. 由于某种原因,它一直说CC不是有效的方法。 object_Mailitem failed. object_Mailitem失败。

  • Editing the variables behind the .cc and .bcc to "mail@x.com" is working without getting the error. 将.cc和.bcc后面的变量编辑为“ mail@x.com”的工作没有错误。 So I assume there is something wrong with the line after the .cc, i've tried multiple solutions which ended up in either the same error or an other error telling me it doesn't recognize the .Send command. 因此,我认为.cc之后的行有问题,我尝试了多种解决方案,但均以相同的错误或另一个错误告终,告诉我它无法识别.Send命令。

EDIT: added the full code of the macro 编辑:添加了宏的完整代码

Sub Send files()
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
Dim ccontvangen As Range

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With

Set sh = Sheets("Sheet1")

Set OutApp = CreateObject("Outlook.Application")

For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)

    Set rng = sh.Cells(cell.Row, 1).Range("E1:Z1")

    If cell.Value Like "?*@?*.?*" And _
        Application.WorksheetFunction.CountA(rng) > 0 Then
        Set OutMail = OutApp.CreateItem(0)
        With OutMail
            .to = cell.Value
            .cc = "x"
            .Subject = "Subject"
            .Attachments.Add "G:\signature.png", olByValue, 0
            .Body = " "

            For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
                If Trim(FileCell) <> "" Then
                    If Dir(FileCell.Value) <> "" Then
                        .Attachments.Add FileCell.Value
                        End If
                    End If
            Next FileCell
             .Send
        End With

            Set OutMail = Nothing
        End If
    Next cell

    Set OutApp = Nothing
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub

I had encountered a similar issue where the Subject Line, To, and Cc were not being listed completely. 我遇到过类似的问题,主题行,收件人和抄送未完全列出。

I figured out the problem by adding a & ";" 我通过添加&“;”解决了问题 to the end of each field. 到每个字段的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM