簡體   English   中英

如何在 VBA 的電子郵件正文中向我的 html 項目符號列表添加填充?

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

我不知道如何在 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>

你可以試試這個,這叫做內聯 css

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

如果您也感興趣,填充也有左、右、頂部和底部選項。 如果你想深入研究 web 開發,我建議你學習 css。

編輯:我現在看到了您的編輯,您可以像這樣使用它。

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

您可以像這樣使用樣式塊和/或內聯 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 字符串構建處理任何轉義。

請注意,您的li項周圍缺少<ul><ol>

這正是我所需要的。 添加了縮進的項目符號並刪除了“產品”行和第一個列表項行之間的換行符。

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

沒有測試您的完整代碼,我只是將其提煉為呈現正確的 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 的樣子:

在此處輸入圖片說明

如果沒有看到實際 VBA 中應用的樣式,很難猜測問題是什么,但是試一試,看看它是否可以代替手動項目符號和縮進的方法。

暫無
暫無

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

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