PDA

View Full Version : Tables.Add Range: X,Y position?



denbihe
06-11-2012, 07:35 AM
Hi everybody,
I'm a bit frustrated to create a different header in every page. So I deciced to put the visuals in the header, and assign a macro to create the text part.

I came up with this macro: which creates a table, writes the text and positions it over the header.
But the problem is I always need to be on the first row. Sometimes I have a table which continues from first page, so I can not run this efficiently.

Is there a way to make
Range:=Selection.Range
not selection but a x,y position maybe?

I need your advices, thanks a lot in advance.



ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
Selection.TypeText Text:="Header 1 Text"
Selection.Tables(1).Select
Selection.Tables(1).Borders.Enable = False
Selection.Tables(1).Rows.HorizontalPosition = -25
Selection.Tables(1).Rows.VerticalPosition = -75
Selection.Font.Name = "Arial"
Selection.Font.Size = 18
Selection.Font.ColorIndex = wdWhite

Tinbendr
06-11-2012, 08:42 AM
Welcome to the board!

Sub test()
Dim Tbl As Table

Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=1, _
NumColumns:=1, DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitFixed)
With Tbl
.Cell(1, 1).Range.Text = "Header 1 Text"
.Borders.Enable = False
.Rows.HorizontalPosition = -25
.Rows.VerticalPosition = -75
With .Range.Font
.Name = "Arial"
.Size = 18
'.ColorIndex = wdWhite
End With
End With
End Sub
When I used the wdWhite, the text was unviewable. Not sure what you are trying to do here.