Excel-Outlook VBA 2013无法在2016年Outlook版本上工作



我的宏有问题。它曾经在2013年版的Outlook和Excel上工作,但由于某种原因,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")

但是,这在2016年版的我的Excel和Outlook中无效。Excel中的每一行都需要从Excel中的一排中选择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没有完全列出。

我通过添加A&amp;弄清楚了这个问题。";"到每个字段的末端。

最新更新