发送带有多个附件的电子邮件

发布于 2025-02-08 17:48:04 字数 774 浏览 1 评论 0原文

我正在使用以下代码发送电子邮件。

我想阅读多个查找附件的单元格。

For i = 2 To n
    Set msg = outlook.createitem(0)
        
    msg.SentOnBehalfOfName = sheet.Range("F" & i).Value
    msg.To = sheet.Range("G" & i).Value
    msg.cc = sheet.Range("H" & i).Value
    msg.Subject = sheet.Range("I" & i).Value
    msg.body = sheet.Range("J" & i).Value
    If sheet.Range("K", i).Value <> "" Then
    msg.attachments.Add sheet.Range("K" & i).Value
    msg.Show

Next i

它适用于任何类型的附件。

如何将其修改为多个文件?

我尝试了一个嵌套的循环,但找不到任何结果。

示例文件路径。

I am using the following code to send emails.

I want to read more than one cell for finding attachments.

For i = 2 To n
    Set msg = outlook.createitem(0)
        
    msg.SentOnBehalfOfName = sheet.Range("F" & i).Value
    msg.To = sheet.Range("G" & i).Value
    msg.cc = sheet.Range("H" & i).Value
    msg.Subject = sheet.Range("I" & i).Value
    msg.body = sheet.Range("J" & i).Value
    If sheet.Range("K", i).Value <> "" Then
    msg.attachments.Add sheet.Range("K" & i).Value
    msg.Show

Next i

It does work for a single attachment of any kind.t

How do I modify it for more than one file?

I tried a nested for loop for it but was unable to find any result.

Example file paths.
results

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千寻… 2025-02-15 17:48:04

如果下一列包含一个附件路径,则可以添加另一个条件,如果要在此处指定的文件附加。

For i = 2 To n
    Set msg = outlook.createitem(0)
        
    msg.SentOnBehalfOfName = sheet.Range("F" & i).Value
    msg.To = sheet.Range("G" & i).Value
    msg.cc = sheet.Range("H" & i).Value
    msg.Subject = sheet.Range("I" & i).Value
    msg.body = sheet.Range("J" & i).Value

    If sheet.Range("K", i).Value <> "" Then
      msg.attachments.Add sheet.Range("K" & i).Value
    
    If sheet.Range("L", i).Value <> "" Then
      msg.attachments.Add sheet.Range("L" & i).Value

    If sheet.Range("O", i).Value <> "" Then
      msg.attachments.Add sheet.Range("O" & i).Value

    msg.Show

Next i

因此,您可以将其进一步推断到工作表上的其他列。

If the next column contains an attachment path you can add yet another if condition to attach the file specified there.

For i = 2 To n
    Set msg = outlook.createitem(0)
        
    msg.SentOnBehalfOfName = sheet.Range("F" & i).Value
    msg.To = sheet.Range("G" & i).Value
    msg.cc = sheet.Range("H" & i).Value
    msg.Subject = sheet.Range("I" & i).Value
    msg.body = sheet.Range("J" & i).Value

    If sheet.Range("K", i).Value <> "" Then
      msg.attachments.Add sheet.Range("K" & i).Value
    
    If sheet.Range("L", i).Value <> "" Then
      msg.attachments.Add sheet.Range("L" & i).Value

    If sheet.Range("O", i).Value <> "" Then
      msg.attachments.Add sheet.Range("O" & i).Value

    msg.Show

Next i

So, you can further extrapolate this to other columns on the sheet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文