简体   繁体   English

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

[英]How can I add padding to my html bullet point list within an email body in VBA?

I can't figure out how to add padding/indents on the two list items below in the html body (lines 4 and 5 of .html body).我不知道如何在 html 正文(.html 正文的第 4 行和第 5 行)中的两个列表项上添加填充/缩进。 It looks like I need to add some padding via CSS, but I do not know how to do that.看起来我需要通过 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

This is basically what I am wanting to do with those two lines, just can't figure out how to specifically write the code within VBA这基本上就是我想要用这两行做的事情,只是不知道如何在 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>

You can try this, this is called inline css你可以试试这个,这叫做内联 css

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

Also padding have left, right, top and bottom options if you are interested in too.如果您也感兴趣,填充也有左、右、顶部和底部选项。 I suggest you learn css, if you are to delve in web development.如果你想深入研究 web 开发,我建议你学习 css。

Edit: I saw your edit now, you can use it like this.编辑:我现在看到了您的编辑,您可以像这样使用它。

<style>
.padding { 
  padding-left: 2px;}
</style>
// Below line will work now
<p class="padding">This text has a left padding of 2 cm.</p>

You can use a style block and/or inline css like this:您可以像这样使用样式块和/或内联 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>"

Single quotes and double quotes are more or less interchangeable in HTML, so use single quotes there to avoid having to deal with any escaping for your VBA string building.单引号和双引号在 HTML 中或多或少是可以互换的,因此在那里使用单引号可以避免为您的 VBA 字符串构建处理任何转义。

Note you're missing <ul> or <ol> around your li items请注意,您的li项周围缺少<ul><ol>

This did exactly what I needed.这正是我所需要的。 Added indented bullet points and removed the line break between the "Products" line and the first list item line.添加了缩进的项目符号并删除了“产品”行和第一个列表项行之间的换行符。

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

Without testing your full code, I just distilled it down to rendering the proper HTML to prove it works.没有测试您的完整代码,我只是将其提炼为呈现正确的 HTML 以证明它有效。 Here is the code that should do it:这是应该执行此操作的代码:

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

And to give you some confidence that it does indent, this is what the rendered HTML looks like in a browser:为了让您确信它确实缩进了,这就是在浏览器中呈现的 HTML 的样子:

在此处输入图片说明

Hard to guess what the issue was without seeing the style applied in the actual VBA, but give this a run and see if it works in lieu of your approach of manual bullets and indentation.如果没有看到实际 VBA 中应用的样式,很难猜测问题是什么,但是试一试,看看它是否可以代替手动项目符号和缩进的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用应用脚本通过html标签将列表添加到电子邮件模板的正文中? 不希望使电子邮件全文 - How do I add list into body of email template via html tags using apps script? Not looking to make entire body of email html 如何在html下拉列表中添加填充? - How can I add padding to html dropdownlist? 使用VBA,如何将选定的Excel单元格发送到具有html格式的电子邮件正文? - using VBA how can I send a selection of Excel Cells to an Email Body with html formatting? 如何在HTML列表中将项目符号点居中? - How can I center the bullet points in an HTML list? 如何使用HTML / CSS为我的网站创建项目符号点? - How can I create bullet points for my website in HTML/CSS? 如何在我的html电子邮件中添加“分段符”? - How can I add “paragraph breaks” to my html email? 如何添加创建博客文章的日期,以取代列表样式类型下的项目符号? - How do I add the date a blog post was created in place of a bullet point under list-style-type? 如何在 email 正文字符串中将列表显示为表格? - How do I a display a list as a table within an email body string? 如何对齐 HTML 项目符号列表中的第二行 - How to align the second line in HTML Bullet point list 我可以使用 CSS 为任何元素添加项目符号吗? - Can I use CSS to add a bullet point to any element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM