View Single Post
 
Old 08-03-2019, 05:20 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

I guess from the reference to 'sh' that you are running this code from Excel, in which case

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


    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
    Set objWord = Nothing
    Set objDoc = Nothing
    Set objRange = Nothing
    Set objTable = 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