Как я могу добавить заполнение в свой список html маркированного списка в теле письма в VBA? - PullRequest
1 голос
/ 08 января 2020

Я не могу понять, как добавить отступы / отступы к двум элементам списка ниже в теле html (строки 4 и 5 в теле html). Похоже, мне нужно добавить некоторые отступы через 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 ]

1 голос
/ 08 января 2020

Вы можете использовать блок стиля и / или встроенный текст 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 предметов

1 голос
/ 08 января 2020

Вы можете попробовать это, это называется inline css

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

Также у отступов есть опции left, right, top и bottom, если вы тоже заинтересованы. Я предлагаю вам научиться 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>
0 голосов
/ 09 января 2020

Не проверяя ваш полный код, я просто перевел его на рендеринг правильного 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, но попробуйте и посмотрите, работает ли он вместо вашего подхода к ручным пулям и отступы.

0 голосов
/ 08 января 2020

Это сделал именно то, что мне нужно. Добавлены точки с отступом и удален разрыв строки между строкой «Продукты» и строкой первого списка.

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...