簡體   English   中英

Excel VBA 代碼從 email 帳戶從 Z038E648F69B23B2A54ZDAF26 發送電子郵件(不工作)。

[英]Excel VBA code to send emails from a specific shared email Account from Outlook not working (.sentonbehalfof)

我的以下代碼可以很好地從我的 excel 文件發送電子郵件。 但是我不知道在哪里添加 .sentonbehalf 行以從我有權發送的特定共享 email 發送。 任何幫助是極大的贊賞。

Sub send_email()
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("Statements")
    
    Dim OA As Object
    Dim msg As Object
    
    Set OA = CreateObject("Outlook.Application")
    Dim each_row As Integer
    Dim last_row As Integer
    last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
  
    For each_row = 2 To last_row
          Set msg = OA.createitem(0)
          msg.To = sh.Range("A" & each_row).Value
          first_name = sh.Range("B" & each_row).Value
          last_name = sh.Range("C" & each_row).Value
          msg.cc = sh.Range("D" & each_row).Value
          msg.Subject = sh.Range("E" & each_row).Value
          msg.body = sh.Range("F" & each_row).Value
          date_to_send = sh.Range("H" & each_row).Value
          date_to_send = Format(date_to_send, "dd/mm/yyyy")
          Status = sh.Range("I" & each_row).Value
          current_date = Format(Date, "dd/mm/yyyy")
          If date_to_send = current_date Then
                If sh.Range("G" & each_row).Value <> "" Then
                msg.attachments.Add sh.Range("G" & each_row).Value
                Cells(each_row, 9).Value = "Sent"
                Content = Replace(msg.body, "<>", first_name + " " + last_name)
                msg.body = Content
                msg.send
            Else
                Cells(each_row, 9).Value = "Sent"
                Content = Replace(msg.body, "<>", first_name + " " + last_name)
                msg.body = Content
                msg.send
            End If
          End If
         
    Next each_row
End Sub

嘗試添加

 msg.SentOnBehalfOfName = "Your shared email address"
 

在這條線之上

 msg.cc = sh.Range("D" & each_row).Value

它對我有用!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM