繁体   English   中英

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

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

我在使用宏时遇到问题。 它曾经可以在Outlook 2013和Excel的2013版本上运行,但由于某些原因,CC功能已停止工作,并且我不断收到错误消息。

在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")

但是,这在我的Excel和Outlook 2016版本中不起作用。 excel中的每一行都需要从Excel中的一行中选择自己的To,CC和BCC。 由于某种原因,它一直说CC不是有效的方法。 object_Mailitem失败。

  • 将.cc和.bcc后面的变量编辑为“ mail@x.com”的工作没有错误。 因此,我认为.cc之后的行有问题,我尝试了多种解决方案,但均以相同的错误或另一个错误告终,告诉我它无法识别.Send命令。

编辑:添加了宏的完整代码

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

我遇到过类似的问题,主题行,收件人和抄送未完全列出。

我通过添加&“;”解决了问题 到每个字段的末尾。

暂无
暂无

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

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