First working with VBA Word via Excel: Not able to insert or add table after a paragrpah or Line

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
638
Hello

This is my First VBA word coding via excel.
Partly Successful because what happens Table OverWrites on the Paragrpah and marked in Red gave me error Object does not support this property
Code:
Private Sub cmdWordformat_Click()
Dim objWord As Word.Application
Dim txtString 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
      
   txtString = " The Brown fox” & vbcrlf  & “quickly Jumped over” & vbcrlf  & “the Lazydogs“
         
    Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
    objWord.Visible = True
    objWord.ActiveDocument.Content.FormattedText.Text = txtString
 Set objRange = objDoc.Range
   
    intRows = 2: intCols = 2
    objDoc.Tables.Add objRange, intRows, intCols
[COLOR=#ff0000][B]    [I]objDoc.Tables.InsertAfter txtString[/I]
[/B][/COLOR]       
    Set objTable = objDoc.Tables(1)
    objTable.Borders.Enable = True

    With objTable
    .Cell(1, 1).Range.Text = "My First Word VBA"
    .Cell(2, 1).Range.Text = "Feedback"
   End With
  Set objWord = Nothing
End Sub
Thanks NimishK
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,223
Messages
5,768,903
Members
425,501
Latest member
sunderlalrwr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top