title: Excel VBA code to send emails from a specific shared email Account from Outlook not working (.sentonbehalfof)
body: <p>I have the below code that works perfectly well sending emails from my excel file. However I do not know where to add the .sentonbehalf of line to send from a specific shared email that I have the access to send from. Any help is greatly appreciated.</p>
  <pre><code>Sub send_email()
      Dim sh As Worksheet
      Set sh = ThisWorkbook.Sheets(&quot;Statements&quot;)
      
      Dim OA As Object
      Dim msg As Object
      
      Set OA = CreateObject(&quot;Outlook.Application&quot;)
      Dim each_row As Integer
      Dim last_row As Integer
      last_row = Application.WorksheetFunction.CountA(sh.Range(&quot;A:A&quot;))
    
      For each_row = 2 To last_row
            Set msg = OA.createitem(0)
            msg.To = sh.Range(&quot;A&quot; &amp; each_row).Value
            first_name = sh.Range(&quot;B&quot; &amp; each_row).Value
            last_name = sh.Range(&quot;C&quot; &amp; each_row).Value
            msg.cc = sh.Range(&quot;D&quot; &amp; each_row).Value
            msg.Subject = sh.Range(&quot;E&quot; &amp; each_row).Value
            msg.body = sh.Range(&quot;F&quot; &amp; each_row).Value
            date_to_send = sh.Range(&quot;H&quot; &amp; each_row).Value
            date_to_send = Format(date_to_send, &quot;dd/mm/yyyy&quot;)
            Status = sh.Range(&quot;I&quot; &amp; each_row).Value
            current_date = Format(Date, &quot;dd/mm/yyyy&quot;)
            If date_to_send = current_date Then
                  If sh.Range(&quot;G&quot; &amp; each_row).Value &lt;&gt; &quot;&quot; Then
                  msg.attachments.Add sh.Range(&quot;G&quot; &amp; each_row).Value
                  Cells(each_row, 9).Value = &quot;Sent&quot;
                  Content = Replace(msg.body, &quot;&lt;&gt;&quot;, first_name + &quot; &quot; + last_name)
                  msg.body = Content
                  msg.send
              Else
                  Cells(each_row, 9).Value = &quot;Sent&quot;
                  Content = Replace(msg.body, &quot;&lt;&gt;&quot;, first_name + &quot; &quot; + last_name)
                  msg.body = Content
                  msg.send
              End If
            End If
           
      Next each_row
  End Sub
  </code></pre>