veer salaria
veer salaria

Reputation: 9

spacing between Tables in word document

'    Set wrdTable1 = objDoc.Tables.Add(objDoc.Range, 20, 2)
    Set wrdTable1 = objDoc.Tables.Add(Range:=objWord.Selection.Range, NumRows:=20, NumColumns:=2, _
         DefaulttableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)

    wrdTable1.Borders.Enable = False

    With wrdTable1.Rows(1)
        .Cells(1).Range.Text = "Tele: @@@@"
        .Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
        .Cells(2).Range.Text = "!@@@@@@##@#"
        .Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With

    wrdTable1.Rows(2).Cells(2).Range.Text = "PIN- 9@@@@@"
    wrdTable1.Rows(3).Cells(2).Range.Text = "##########"
    wrdTable1.Rows(20).Cells.Merge
    wrdTable1.Rows(20).Cells(1).Range.Text = "2.   It is under ref :-"
    wrdTable1.Rows(20).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify

    wrdTable1.Range.InsertParagraphAfter

    Set wrdTable2 = objDoc.Tables.Add(wrdTable1.Range.Next, ntotalRecords, ntotalColumns) 
    Dim intRow As Integer
    Dim intCol As Integer

    With wrdTable2

        intCtr = 1: intRow = 1
        While (Sheets("SummaryDVBan").Cells(intCtr, 11).FormulaR1C1 <> "")

            For intCol = 1 To ntotalColumns

                .cell(intRow, intCol).Range.InsertAfter Sheets("SummaryDVBan").Cells(intCtr, intCol + 10).FormulaR1C1

            Next intCol

        intCtr = intCtr + 1
        intRow = intRow + 1
        Wend

        .Columns(1).SetWidth 40, wdAdjustFirstColumn
        .Columns(2).SetWidth 120, wdAdjustFirstColumn
        .Columns(3).SetWidth 60, wdAdjustFirstColumn
        .Columns(4).SetWidth 90, wdAdjustFirstColumn
        .Columns(5).SetWidth 65, wdAdjustFirstColumn
        .Columns(6).SetWidth 60, wdAdjustFirstColumn
        .Columns(7).SetWidth 90, wdAdjustFirstColumn

        .Style = "Table Grid"
        .Borders.Enable = True
        .Rows(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Rows(1).Range.Bold = True
        .Rows(1).HeadingFormat = True
        .Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
        .Borders.InsideLineStyle = wdLineStyleSingle

    End With
    wrdTable2.Range.InsertParagraphAfter

    Set wrdTable3 = objDoc.Tables.Add(wrdTable2.Range.Next, 7, 4) ' insert table 3
    wrdTable3.Borders.Enable = False

    w = wrdTable3.Rows(1).Cells(1).Width * 4
    w1 = w * 0.26

    For X = 1 To 7
       With wrdTable3.Rows(X)
            .Cells(1).Width = w1
            .Cells(2).Width = w1
            .Cells(3).Width = w1
            .Cells(4).Width = w1
            .Height = 16
        End With
    Next X

    wrdTable3.Rows(1).Cells.Merge
    wrdTable3.Rows(1).Cells(1).Range.Text = "3.   The confirmation at the earliest pl."
    wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
    wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
    wrdTable3.Rows(1).Cells(1).Range.ParagraphFormat.LineSpacing = 18

    

    With objDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range
        .Text = "REQUEST REMINDER"
        .ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Font.Bold = True
        .Font.Name = "Arial"
        .Font.Size = 12
        .Font.Underline = wdUnderlineSingle
        .InsertParagraphAfter
        .ParagraphFormat.SpaceAfter = 12          ' twice the font size for 1 "blank line"
    End With

End Sub

the above code adds three tables into the word document however, the output document is showing the first two tables as joint. Also the when the table2 is spilling over the next page the output word document has the first table being repeated again on the second page. the first table is also being shown with gridlines despite the gridlines set as false.

In the output first and third table is to be without gridlines. first and second table needs to have space between them. the second table is with gridlines. and the first table is not required to repeat itself

Upvotes: 0

Views: 65

Answers (1)

wrbp
wrbp

Reputation: 890

Use the document to insert the paragraph and a section break, and also use the document to reference the range to add the next table

    objDoc.Paragraphs.Last.Range.InsertParagraphAfter
    objDoc.Paragraphs.Last.Range.InsertBreak Type:=wdSectionBreakContinuous

    Dim rng As Range
    Set rng = objDoc.Range(objDoc.Paragraphs.Last.Range.Start, objDoc.Paragraphs.Last.Range.End)
    Set wrdTable2 = objDoc.Tables.Add(rng, ntotalrecords, ntotalColumns)
    Dim intRow As Integer
    Dim intCol As Integer

Upvotes: 0

Related Questions