Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2012, 03:14 PM
macropod's Avatar
macropod macropod is online now Word VBA: add textboxs in table cells? Windows 7 64bit Word VBA: add textboxs in table cells? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,362
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

The following works for me:


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
Dim tbl As Word.Table
Dim Shp As Word.Shape
Dim Rng As Word.Range
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
    Set Rng = .Cell(2, 2).Range
    Rng.Collapse wdCollapseStart
  End With
  Set Shp = oDoc.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
    Left:=0, Top:=0, Width:=72, Height:=12, Anchor:=Rng)
  With Shp
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    .RelativeVerticalPosition = wdRelativeVerticalPositionPage
  End With
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 02-07-2012, 06:34 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

Quote:
Originally Posted by macropod View Post
Hi tinfanide,

The following works for me:
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
Dim tbl As Word.Table
Dim Shp As Word.Shape
Dim Rng As Word.Range
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
    Set Rng = .Cell(2, 2).Range
    Rng.Collapse wdCollapseStart
  End With
  Set Shp = oDoc.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
    Left:=0, Top:=0, Width:=72, Height:=12, Anchor:=Rng)
  With Shp
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    .RelativeVerticalPosition = wdRelativeVerticalPositionPage
  End With
End With
End Sub
Following the codes by copy and paste, I could still not get the result wanted. Please take a look at how it fails to work.

Eventually I fixed it in a way that I didn't think was the best solution.

What I have expected is still get the textbox positioned relative to the targetted table cell.


http://www.youtube.com/watch?v=Hgv-LsQ9tTE&hd=1
Reply With Quote
Reply



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 04:18 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