View Single Post
 
Old 02-06-2012, 01:41 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

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.
Reply With Quote