Home > Net >  Issue with MS Access coding for 2 separate tables
Issue with MS Access coding for 2 separate tables

Time:02-01

I am trying to add 2 tables into my code for an automate email. However, the result comes out as a table in a table with no borders. I am unable to get them separated with borders.

The following is my result and syntax :

enter image description here

  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 = ""

I have tried adding the selection.TypeParagraph function but the line breaks just keep adding inside the table, not after or before the table.

CodePudding user response:

Using Word objects and properties seems overly complex for Outlook message. Here is example of building two tables using HTML code tags.

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>"

  • Related