View Single Post
 
Old 08-03-2019, 02:21 AM
SamDsouza SamDsouza is offline Windows 10 Office 2013
Advanced Beginner
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default syntax for inserting blank line before inserting table and after a line or paragraph

Hi Guys

As this is my First post for VBA for word

Just wanted to have syntax for inserting blank line after a line/or paragraph typed
and also to insert a blank line before table is inserted and after line typed or paragraph

Code:
Private Sub InsertingBlankLine()
Dim objWord As Word.Application
Dim txtword As String, sh As Worksheet
Dim objDoc As Document
Dim objRange As Range
Dim objTable As Table
Dim intRows As Integer
Dim intCols As Integer


txtWord = "fsdhfkhfkdhfdskfhd fkdshfdkfhdskfhdsfd fdshgfdjdsjfg"
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Add
    objWord.Visible = True
    objWord.ActiveDocument.Content.FormattedText.Text = txtWord
 Set objRange = objDoc.Range

    Set objRange = objDoc.Content
    
    objRange.Collapse Direction:=wdCollapseEnd

'How to insert blank line here

    intRows = 8: intCols = 5
    objDoc.Tables.Add objRange, intRows, intCols

    Set objTable = objDoc.Tables(1)
    objTable.Borders.Enable = True

    Set objWord = Nothing
End Sub
Thanks and regards
SamD
Reply With Quote