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
684
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 fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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
Back
Top