Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 02-06-2012, 04:28 AM
tinfanide tinfanide is offline Word VBA: add textboxs in table cells? Windows 7 64bit Word VBA: add textboxs in table cells? Office 2010 32bit
Expert
Word VBA: add textboxs in table cells?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Code:
Sub TypeTextTypeUnderline()
 
Dim File As String
File = "C:\Users\Tin\Desktop\a.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 tbl As Word.Table
Dim Shp As Shape, Rng As Range
With ActiveDocument
 
    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

''' Runtime Error 13
''' Error: Type Mismatch
    Set Rng = .Tables(1).Cell(2, 2).Range
''' It seems Table.Cell.Range cannot be set to Range

    Rng.Collapse wdCollapseStart
    
    Set Shp = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
    Left:=0, Top:=0, Width:=72, Height:=12, Anchor:=Rng)
    
    With Shp
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .RelaitveVerticalPosition = wdRelativeVerticalPositionPage
    End With
 
 
End With
 
End Sub
I type the VBA codes in Excel.
It shows error in Word (please see the comments above within the codes).
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA: add textboxs in table cells? put a border around table cells that have text in them tonywatsonmail Mail Merge 1 01-31-2012 04:37 AM
Word VBA: add textboxs in table cells? Unwanted tabs in table cells deltaskye Word 5 01-27-2012 11:58 AM
Word VBA: add textboxs in table cells? Combining Text from Table Cells robmorleyuk Word 1 11-01-2011 07:24 AM
Word VBA: add textboxs in table cells? Copy table cell formatting across multiple cells / tables pakistanray Word Tables 2 10-31-2011 08:07 AM
Word VBA: add textboxs in table cells? Share your tips for centering images in table cells WaltR Word 4 01-29-2011 11:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft