View Single Post
 
Old 08-03-2019, 03:03 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your code can be a lot simpler. If you are running the code from Word, there is no need to create the application.
You could use Range.InsertParagraphAfter but it is just as easy to include a paragraph mark with the text you are inserting.
Code:
Private Sub InsertingBlankLine()
Dim objWord As Word.Application
Dim txtword As String
Dim objDoc As Document
Dim objRange As Range
Dim objTable As Table
Dim intRows As Integer
Dim intCols As Integer

    txtWord = "fsdhfkhfkdhfdskfhd fkdshfdkfhdskfhdsfd fdshgfdjdsjfg" & vbCr
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set objDoc = objWord.Documents.Add
    objDoc.Range.Text = txtWord
    Set objRange = objDoc.Range    
    objRange.Collapse Direction:=wdCollapseEnd
    intRows = 8: intCols = 5
    Set objTable = objDoc.Tables.Add(objRange, intRows, intCols)
    objTable.Borders.Enable = True
End Sub
Also not sure why you remove the objWord but don't save or close the Word doc, nor remove the other objects you created along the way.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote