我正在尝试将两个带边框的表格添加到我的电子邮件代码中。
结果显示为无边框表格中的表格。
以下是我的结果和语法:
myitem.Display
Set ins = oOutlook.ActiveInspector
Set document = ins.WordEditor
Set Word = document.Application
Set selection = Word.selection
selection.TypeText Text:="Dear Requester,"
selection.TypeParagraph
selection.TypeParagraph
With selection
.Font.Bold = True
End With
selection.TypeText Text:="Please confirm that quotation of chosen vendor is suitable before proceeding with PR creation."
selection.TypeParagraph
selection.TypeParagraph
'add table here
Set objTable = selection.Tables.Add(Range:=selection.Range, NumRows:=3, NumColumns:=2)
objTable.Borders.OutsideLineStyle = wdLineStyleSingle
objTable.Borders.OutsideLineWidth = wdLineWidth150pt
objTable.Borders.OutsideColor = wdColorBlack
objTable.Cell(1, 1).Range.Text = "Initial quote :"
objTable.Cell(1, 2).Range.Text = " "
objTable.Cell(2, 1).Range.Text = "Discount rate :"
objTable.Cell(2, 2).Range.Text = ""
objTable.Cell(3, 1).Range.Text = "Final quote :"
objTable.Cell(2, 2).Range.Text = ""
selection.TypeParagraph
selection.TypeParagraph
Set objTable2 = selection.Tables.Add(Range:=selection.Range, NumRows:=2, NumColumns:=2)
objTable2.Borders.OutsideLineStyle = wdLineStyleSingle
objTable2.Borders.OutsideLineWidth = wdLineWidth150pt
objTable2.Borders.OutsideColor = wdColorBlack
objTable2.Cell(1, 1).Range.Text = "Last spend on year 2020 :"
objTable2.Cell(1, 2).Range.Text = " "
objTable2.Cell(2, 1).Range.Text = "Incremental increase percentage :"
objTable2.Cell(2, 2).Range.Text = ""
我尝试添加
selection.TypeParagraph
函数,但换行符不断在表格内添加,而不是在表格之后或之前。
对于 Outlook 消息来说,使用 Word 对象和属性似乎过于复杂。这是使用 HTML 代码标签构建两个表的示例。
Dim strT As String, strC As String, strH As String
strT = "width='500' style='text-align:left;border:2px;font-family:calibri;border-collapse:collapse;padding:5px'"
strC = "style='border:3px solid black' width='50%'"
strH = "<table " & strT & ">" & _
"<tr><td " & strC & ">Initial quote : </td><td " & strC & "></td></tr>" & _
"<tr><td " & strC & ">Discount rate : </td><td " & strC & "></td></tr>" & _
"<tr><td " & strC & ">Final quote : </td><td " & strC & "></td></tr></table><br>" & _
"<table " & strT & ">" & _
"<tr><td " & strC & ">Last spend on year 2020 : </td><td " & strC & "></td></tr>" & _
"<tr><td " & strC & ">Increment increase percentage : </td><td " & strC & "></td></tr>" & _
"<tr><td " & strC & ">Final quote : </td><td " & strC & "></td></tr></table>"
决定将 2 个表合并为 1 个表。留空行。
myitem.Display
Set ins = oOutlook.ActiveInspector
Set document = ins.WordEditor
Set Word = document.Application
Set selection = Word.selection
selection.TypeText Text:="Dear Requester,"
selection.TypeParagraph
selection.TypeParagraph
With selection
.Font.Bold = True
End With
selection.TypeText Text:="Please confirm that quotation of chosen vendor is suitable before proceeding with PR creation."
selection.TypeParagraph
selection.TypeParagraph
'add table here
With selection.Tables.Add(Range:=selection.Range, NumRows:=6, NumColumns:=2)
.Range.Font.Bold = True
.Cell(1, 1).Range.Text = "Initial quote"
.Cell(1, 2).Range.Text = ""
.Cell(2, 1).Range.Text = "Discount rate"
.Cell(2, 2).Range.Text = ""
.Cell(3, 1).Range.Text = "Final quote"
.Cell(3, 2).Range.Text = ""
.Cell(4, 1).Range.Text = ""
.Cell(4, 2).Range.Text = ""
.Cell(5, 1).Range.Text = "Last spend on year _2020_ :"
.Cell(5, 2).Range.Text = ""
.Cell(6, 1).Range.Text = "Incremental increase percentage :"
.Cell(6, 2).Range.Text = ""
End With