Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从excel到outlook的HTML VBA代码填充到:_Html_Excel_Vba_Outlook_Sendmail - Fatal编程技术网

从excel到outlook的HTML VBA代码填充到:

从excel到outlook的HTML VBA代码填充到:,html,excel,vba,outlook,sendmail,Html,Excel,Vba,Outlook,Sendmail,我有下面的代码,它由excel工作簿中的按钮激活。 该按钮提取所需信息并传输到Outlook中的表。但是,我无法确定如何将excel中的M列(电子邮件地址)编码到电子邮件的“至””字段 Sub Email() Const HEADER_ROW As Long = 15 '<< the row with column headers Const NUM_COLS As Long = 8 '<< how many columns of data

我有下面的代码,它由excel工作簿中的按钮激活。 该按钮提取所需信息并传输到Outlook中的表。但是,我无法确定如何将excel中的M列(电子邮件地址)编码到电子邮件的“至””字段

Sub Email()

    Const HEADER_ROW As Long = 15 '<< the row with column headers
    Const NUM_COLS As Long = 8   '<< how many columns of data

    Const olMailItem = 0
    Const olFolderInbox = 6

    Dim ol As Object, fldr, ns, msg
    Dim html As String, c As Range, colReq As Long, hdr As Range
    Dim rw As Range

    On Error Resume Next
    Set ol = GetObject(, "outlook.application")
    On Error GoTo 0

    If ol Is Nothing Then
        On Error Resume Next
        Set ol = CreateObject("outlook.application")
        Set ns = ol.GetNamespace("MAPI")
        Set fldr = ns.GetDefaultFolder(olFolderInbox)
        fldr.Display
        On Error GoTo 0
    End If

    If ol Is Nothing Then
        MsgBox "Couldn't start Outlook to compose mail!", vbExclamation
        Exit Sub
    End If

    Set msg = ol.CreateItem(olMailItem)

    Set rw = Selection.Cells(1).EntireRow
msg.To = ""
    msg.Subject = "Hapag Lloyd UK Haulage Issue Alert"

    html = "<style type='text/css'>"
    html = html & "body, p {font:10pt calibri;padding:40px;}"
    html = html & "table {border-collapse:collapse}"
    html = html & "td {border:1px solid #000;padding:4px;}"
    html = html & "</style>"

    html = html & "<p>Dear Sir / Madam,"
    html = html & "<p>Please see below reported transport issue:</p>"
    html = html & "<table>"



    For Each c In rw.Cells(1).Resize(1, NUM_COLS).Cells
        If c.Column <> 10 Then '<<< EDIT to exclude ColD
            Set hdr = rw.Parent.Cells(HEADER_ROW, c.Column) '<< get the header text for this cell

            html = html & "<tr><td style='background-color:#DDD;width:200px;'>" & _
               hdr.Text & _
               "</td><td style='width:400px;'>" & Trim(c.Text) & "</td></tr>"
        End If 'we want this cell
    Next c

    html = html & "</table>"
html = html & "<p>If an ETA is not shown above please revert with your latest acceptance within 30 minutes of this email. </p>"
html = html & "<p>Kind Regards, </p>"
html = html & "<p>Hapag Lloyd UK Haulage Alert Team."
html = html & "<p>Late.Run@hlag.com </p>"
html = html & "<p>0208-507-4000 > Option 4 </p>"
    msg.htmlbody = html
    msg.Display
    Email_To = "ActiveSheet.Range M16"


End Sub
Sub-Email()
Const HEADER_行长=15'选项4

“ msg.htmlbody=html msg.Display 电子邮件发送至=“ActiveSheet.Range M16” 端接头

谢谢

首先,您需要获得格式良好的html标记,其中包含
标记等。只有这样,您才能将其分配给mail item类的
HTMLBody
属性

设置“到”字段有两种主要方式:

  • 使用
    To
    属性

    msg.To = ActiveSheet.Range("M16")
    
  • 使用
    收件人。添加
    方法


  • 类似于
    msg.To=ActiveSheet.Range(“M16”)
    ?我不确定您最初为什么有
    msg.To=”“
    或者你想用
    电子邮件做什么?=…
    。谢谢尤金,这么简单的回答!M列始终在同一行中包含问题的电子邮件地址-因此,当按下第17行上的按钮(即M17/M18等)时,我如何请求宏在M列中的外观?谢谢,有人能帮我解决上述问题吗?