View Single Post
 
Old 08-03-2019, 08:04 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

To add a line after the table, you need to reset the range e.g.

Code:
Private Sub InsertingBlankLine()
Dim objWord As Object
Dim txtword As String, sh As Worksheet
Dim objDoc As Object
Dim objRange As Object
Dim objTable As Object
Dim intRows As Integer
Dim intCols As Integer
Dim oCell As Object

    txtword = "fsdhfkhfkdhfdskfhd fkdshfdkfhdskfhdsfd fdshgfdjdsjfg"
    On Error Resume Next
    Set objWord = GetObject(, "Word.Application")
    If Err Then
        Set objWord = CreateObject("Word.Application")
    End If
    On Error GoTo 0

    Set objDoc = objWord.Documents.Add
    objWord.Visible = True
    Set objRange = objDoc.Range
    With objRange
        .Text = txtword & vbCr    'add the paragraph break at the end of the text string
        .collapse Direction:=0
    End With
    intRows = 8: intCols = 5
    Set objTable = objDoc.Tables.Add(objRange, intRows, intCols)
    '''''''objTable.Borders.Enable = True

    With objTable
        .Borders.Enable = True
        Set oCell = .Cell(1, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 1"
        oCell.Bold = True
        Set oCell = .Cell(2, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 2"
        Set oCell = .Cell(3, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 3"
        Set oCell = .Cell(4, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 4"
        Set oCell = .Cell(5, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 5"
        Set oCell = .Cell(6, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 6"
        Set oCell = .Cell(7, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 7"
        Set oCell = .Cell(8, 1).Range
        oCell.End = oCell.End - 1
        oCell.Text = "row 8"

        .Range.Font.Name = "Tahoma"
        .Range.Font.Size = 15
    End With


    '''''Here also  i would like blank line and start
    txtword = "Paragraph / Line after table"

    Set objRange = objDoc.Range

    With objRange
        .collapse Direction:=0
        .Text = txtword & vbCr    'add the paragraph break at the end of the text string
    End With
    '''''The above range started in the table of 1st Row

    Set objWord = Nothing
    Set objDoc = Nothing
    Set objRange = Nothing
    Set objTable = Nothing
    Set oCell = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote