如何在VBA的电子邮件正文中的HTML项目符号列表中添加填充?

时间:2020-01-08 18:21:29

标签: html css vba outlook

我不知道如何在html正文(.html正文的第4行和第5行)下面的两个列表项上添加填充/缩进。看来我需要通过CSS添加一些填充,但是我不知道该怎么做。

Sub Email_File()
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailAddress As String
    Dim xMailAddress2 As String
    Dim wb1 As Workbook
    Dim attch As String
    Dim subj As String

    Set wb1 = Workbooks("IOM Denial.xlsm")
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailAddress = Workbooks("IOM Denial.xlsm").Sheets("Home").Range("B7").Value
    xMailAddress2 = Workbooks("IOM Denial.xlsm").Sheets("Home").Range("B13").Value
    attch = wb1.Sheets("Home").Range("B21").Value
    subj = wb1.Sheets("Home").Range("B17")


    With xOutMail
        .To = xMailAddress
        .CC = xMailAddress2
        .BCC = ""
        .Subject = subj
        .HTMLBody = "<p>Operations Leadership,</p>" & _
                    "<p>An inventory performance summary of your submitted IOM requested products is attached. The IOM Summary tab displays the families that are approved or denied based on whether they met the minimum performance turn threshold.</p>" & _
                    "Products are evaluated for performance by family" & _
                    "<li>Approved products will be scheduled the same as before, based on forecast availability and prioritized by tier productivity</li>" & _
                    "<li>Denied products are due to a minimum turn threshold of productivity that is not met</li>" & _
                    "<p>Attached is an inventory performance report based on the family of products that are requested in the associated IOM.  This includes your turn and tier performance, inventory and sales information, the minimum turn threshold and national rank for your territory and decision of Yes/No for approval.</p>" & _
                    "<p>In addition - we have included three tabs that provide potential opportunities for redeployment within your territory.  Each tab report shows your productivity in each family: by account, by demand model (SISO) and evaluating loose shelf inventory and/or inventory contained in sales team and sales associate locations.</p>" & _
                    "<p>For those product families where the turn threshold is not met, (NO in column J) please review the performance metrics.  Utilizing the 3 tabs, evaluate the productivity of the identified Parked account turns, site demand model kit delta and misc inventory locations that carry this product family and work to reallocate / rebalance the inventory to meet the need of this particular IOM.</p>"
        .Attachments.Add attch
        .Display '.Send
    End With


    Set xOutMail = Nothing
    Set xOutApp = Nothing

End Sub

这基本上就是我想用这两行来做的,只是无法弄清楚如何在VBA中专门编写代码

<html>
<head>
<style>
p.padding {
  padding-left: 2cm;}
</style>
</head>
<body>

<h1>The padding-left Property</h1>

<p>This is a text with no left padding.</p>
<p class="padding">This text has a left padding of 2 cm.</p>

</body>
</html>

4 个答案:

答案 0 :(得分:1)

您可以尝试一下,这称为嵌入式CSS

robocopy /S "D:\Source" "D:\Destination" "*.*"

如果您也有兴趣,还可以使用padding的左,右,顶部和底部选项。如果您想学习Web开发,建议您学习CSS。

编辑:我现在看到了您的编辑,您可以像这样使用它。

<li style="padding-left:5px"> your texts </li>

答案 1 :(得分:1)

您可以使用样式块和/或嵌入式CSS,如下所示:

.HTMLBody = "<style type='text/css'> li.padded {margin-left:70px}; p.padded {margin-left:100px};</style>" & _
         "<p>Paragraph 1</p>" & _
         "<p>Paragraph 2</p>" & _
         "Products are evaluated for performance by family" & _
         "<ul><li class='padded'>List item 1</li>" & _
         "<li style='margin-left:50px'>List item2</li>" & _
         "</ul><p>Paragraph 3</p>" & _
         "<p>Paragraph 4</p>" & _
         "<p class='padded'>Paragraph 5</p>"

单引号和双引号在HTML中或多或少是可互换的,因此在其中使用单引号可以避免为VBA字符串构建而进行的任何转义。

请注意,您在<ul>个项目中缺少<ol>li

答案 2 :(得分:0)

这正是我需要的。添加了缩进的项目符号点,并删除了“产品”行和第一个列表项行之间的换行符。

With xOutMail
        .To = xMailAddress
        .CC = xMailAddress2
        .BCC = ""
        .Subject = subj
        .HTMLBody = "<html> <head> <style> li.padding { margin-top: -10px; } </style> </head>" & "<p>Operations Leadership,</p>" & _
                    "<p>An inventory performance summary of your submitted IOM requested products is attached. The IOM Summary tab displays the families that are approved or denied based on whether they met the minimum performance turn threshold.</p>" & _
                    "Products are evaluated for performance by family<br>" & _
                    "<ul><li class='padding'>Approved products will be scheduled the same as before, based on forecast availability and prioritized by tier productivity<br>" & _
                    "<li>Denied products are due to a minimum turn threshold of productivity that is not met" & _
                    "</ul><p>Attached is an inventory performance report based on the family of products that are requested in the associated IOM.  This includes your turn and tier performance, inventory and sales information, the minimum turn threshold and national rank for your territory and decision of Yes/No for approval.</p>" & _
                    "<p>In addition - we have included three tabs that provide potential opportunities for redeployment within your territory.  Each tab report shows your productivity in each family: by account, by demand model (SISO) and evaluating loose shelf inventory and/or inventory contained in sales team and sales associate locations.</p>" & _
                    "<p>For those product families where the turn threshold is not met, (NO in column J) please review the performance metrics.  Utilizing the 3 tabs, evaluate the productivity of the identified Parked account turns, site demand model kit delta and misc inventory locations that carry this product family and work to reallocate / rebalance the inventory to meet the need of this particular IOM.</p>"
        .Attachments.Add attch
        .Display '.Send
    End With

答案 3 :(得分:0)

在不测试您的完整代码的情况下,我只是将其简化为呈现正确的HTML以证明其有效。这是应该执行的代码:

Dim html As String

html = "<html> <head> <style> li.padding { padding-left: 2cm; } </style> </head>"

html = html & "<p>Operations Leadership,</p>" & _
       "<p>An inventory performance summary of your submitted IOM requested products is attached." & _
       "The IOM Summary tab displays the families that are approved or denied based on whether they met the minimum performance turn threshold.</p>" & _
       "Products are evaluated for performance by family" & _
       "<li class='padding'>Approved products will be scheduled the same as before, based on forecast availability and prioritized by tier productivity</li>" & _
       "<li class='padding'>Denied products are due to a minimum turn threshold of productivity that is not met</li>" & _
       "<p>Attached is an inventory performance report based on the family of products that are requested in the associated IOM.  " & _
       "This includes your turn and tier performance, inventory and sales information, " & _
       "the minimum turn threshold and national rank for your territory and decision of Yes/No for approval.</p>" & _
       "<p>In addition - we have included three tabs that provide potential opportunities for redeployment within your territory.  " & _
       "Each tab report shows your productivity in each family: by account, by demand model (SISO) and evaluating loose shelf " & _
       "inventory and/or inventory contained in sales team and sales associate locations.</p>" & _
       "<p>For those product families where the turn threshold is not met, (NO in column J) please review the performance metrics.  " & _
       "Utilizing the 3 tabs, evaluate the productivity of the identified Parked account turns, site demand model kit delta and misc inventory " & _
       "locations that carry this product family and work to reallocate / rebalance the inventory to meet the need of this particular IOM.</p>"

html = html & "</body> </html>"

Open "c:\cdh\foo.html" For Output As #1
Print #1, html
Close #1

为了使您确信它确实会缩进,这就是在浏览器中呈现的HTML的样子:

enter image description here

很难在没有看到实际VBA中应用的样式的情况下猜测问题出在哪里,但是可以尝试一下,看看它是否可以代替您的手动项目符号和缩进方法。

相关问题