Excel 更改电子邮件中的引用列

Excel 更改电子邮件中的引用列,excel,vba,Excel,Vba,我试图修改代码,将“J”列用作参考列,但收效甚微。我不确定让代码使用“J”列而不是“A”列缺少了什么。一切正常,代码仍然引用列“A”来获取要发送到的电子邮件地址 Sub EmailItems() 'Creates emails, attaches items, and choice to send automatically or have them pop up for your review. Delete the "'" in front of .Send in order to se

我试图修改代码,将“J”列用作参考列,但收效甚微。我不确定让代码使用“J”列而不是“A”列缺少了什么。一切正常,代码仍然引用列“A”来获取要发送到的电子邮件地址

Sub EmailItems()

'Creates emails, attaches items, and choice to send automatically or have them pop up for your 
review. Delete the "'" in front of .Send in order to send automatically

Dim MailDest As String
Dim subj As String
Dim att As Variant
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim lastRow As Long

lastRow = ThisWorkbook.Worksheets("Email").Cells(Rows.Count, "J").End(xlUp).Row 

For i = 2 To lastRow

    Set OutLookApp = CreateObject("Outlook.application")
    Set OutLookMailItem = OutLookApp.CreateItem(0)
    Set Attach = OutLookMailItem.Attachments

    With OutLookMailItem
        .SentOnBehalfOfName = [O6]
        .To = Cells(i, 1).Value
        .Subject = [O5]
        .Body = [O7] & vbNewLine & vbNewLine & [O9] & vbNewLine & vbNewLine & [O11] & vbNewLine & 
             vbNewLine & [O13] & vbNewLine & [O14] & vbNewLine & [O15] & vbNewLine & [O16]
        On Error Resume Next
            For Each att In Split(Cells(i, 2).Value, ",")
            Attach.Add [O2] & att & [O3]
        Next
        .Display
        On Error GoTo 0
        '.Send
    End With

Next

End Sub
使用以下代码:

Sub EmailItems()

'Creates emails, attaches items, and choice to send automatically or have them pop up for your 
review. Delete the "'" in front of .Send in order to send automatically

Dim MailDest As String
Dim subj As String
Dim att As Variant
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim lastRow As Long

lastRow = ThisWorkbook.Worksheets("Email").Cells(Rows.Count, "J").End(xlUp).Row 

For i = 2 To lastRow

    Set OutLookApp = CreateObject("Outlook.application")
    Set OutLookMailItem = OutLookApp.CreateItem(0)
    Set Attach = OutLookMailItem.Attachments

    With OutLookMailItem
        .SentOnBehalfOfName = [O6]
        .To = Cells(i, 10).Value
        .Subject = [O5]
        .Body = [O7] & vbNewLine & vbNewLine & [O9] & vbNewLine & vbNewLine & [O11] & vbNewLine & 
             vbNewLine & [O13] & vbNewLine & [O14] & vbNewLine & [O15] & vbNewLine & [O16]
        On Error Resume Next
            For Each att In Split(Cells(i, 2).Value, ",")
            Attach.Add [O2] & att & [O3]
        Next
        .Display
        On Error GoTo 0
        '.Send
    End With

Next

End Sub

.To=Cells(i,1)。Value
应该是
.To=Cells(i,10)。Value
我也做了这个更改,但没有成功。现在代码不会创建任何电子邮件。J列中是否有电子邮件地址?行唯一会改变的是它从何处获取收件人。无论哪种方式,我都会使引用显式。可能会解决这个问题,如果没有,那么请仔细查看代码中的哪些地方丢失了。添加显式引用是有效的。谢谢你的帮助,我从来没有想过。