Draw Table

L

LEU

I tried to record a macro that would draw a table at a set location in a
document. But when I click on the record macro button the draw table option
goes away. I have the following macro that lets me draw a shape at a set
location in my document. How would I do the same for a table?

Sub Signoff1()
Dim idx As Integer
Dim oFFline As Shape
Dim i
On Error GoTo endthis
i = Selection.Information(wdVerticalPositionRelativeToPage)
Set oFFline = ActiveDocument.Shapes.AddLine(554, i + 12, 524, i + 12).Line
With oFFline.Line
.Weight = 0.75
End With
oFFline.Name = "hline" & idx
idx = idx + 1
endthis:
End Sub
 
D

Doug Robbins - Word MVP

The following inserts a two row, two column table at the location of the
selection:

ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=2


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LEU

Thank you for responding Doug,

The problem with what you said is that I have text on the left half of the
page and creating a table on the right side is it splits me paragraph. If I
use the draw table, this does not happen and it anchors it at the correct
location in my paragraph. That way if the paragraphs on the left side of the
pages change, the table stays with the correct paragraph. I am using the
table as a single row and column as it will expand or contract as I add or
remove text.

LEU
 
D

Doug Robbins - Word MVP

Maybe this gets closer to what you are after:

Dim atable As Table
Dim tablewidth As Long
With ActiveDocument.PageSetup
tablewidth = .PageWidth - .LeftMargin - .RightMargin
End With
tablewidth = tablewidth -
Selection.Information(wdHorizontalPositionRelativeToTextBoundary)

Set atable = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=1,
NumColumns:=1)
With atable
.Rows.Alignment = wdAlignRowRight
.Rows.WrapAroundText = True
.Cell(1, 1).Width = tablewidth - 20
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LEU

Doug,

I was going about this all wrong. I should be drawing a textbox. I created
the following macro and it almost works. If I use the macro on the first
paragraph at the top of the page everything lines up correctly. But as I use
it down the page the alignment gets farther off each time I use it. In the
first paragraph the text aligns with the text in the textbox. The next time
the text in the textbox is about 1/4 of the high of the lettering lower than
the text in the paragraph and then the next one is even lower. Any ideas on
what the problem is?

Sub NoteBox()
Dim i As Long
i = Selection.Information(wdVerticalPositionRelativeToPage)
ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 394.25, _
i, 194.25, i).Select
Selection.ShapeRange.TextFrame.TextRange.Select
Selection.Collapse
Selection.ShapeRange.Select
Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Line.Visible = msoFalse
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Left = InchesToPoints(4.98)
'Selection.ShapeRange.Top = InchesToPoints(0.159)
Selection.ShapeRange.TextFrame.AutoSize = True
Selection.ShapeRange.TextFrame.WordWrap = True
End Sub


LEU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top