Code:
Sub test()
Dim File As String
File = "C:\Users\Tin\Desktop\Testing.docx"
Dim oWord As Word.Application
Set oWord = New Word.Application
Dim oDoc As Word.Document
Set oDoc = oWord.Documents.Open(File)
oWord.Visible = True
oDoc.Activate
Dim lLeft As Long
Dim tbl As Word.Table
With oDoc
Set tbl = .Tables.Add(Range:=.Range, _
NumRows:=2, _
NumColumns:=2, _
DefaultTableBehavior:=wdWord8TableBehavior)
With tbl
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle
.Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
End With
lLeft = tbl.Cell(2, 2).Range.Information(wdHorizontalPositionRelativeToPage)
.Shapes.AddTextbox Orientation:=msoTextOrientationHorizontal, Left:=lLeft, _
Top:=6, Width:=72, Height:=12, Anchor:=tbl.Cell(2, 2).Range.Characters.First
End With
End Sub
I have automated adding textboxes of Word in Excel VBA.
It seems to have put the textbox on the top left of the document. It does not put within the table cell.