L
Lynn
I have a word formate template, used for theseses. It's based on an old
format for theseses. In the template there are a few macros too. (I didn't
create them). One of them is a table format macro, working fine. (Copied from
the former template.)
Problem is (in former and in new template) that tables are too wide. The
left vertical line is too far out to the left (in the margin). (Since top and
bottom lines are visible they stick out...)
I've managed to record a macro of my own, same table format. While recording
the macro it seems like I manage to change the width, but when running the
macro it's too wide again. So probably I'm only changing that exact table,
and not the macro itself.
The code doesn't help me either. The old table macro is very simple, while
the one I make myself contains every single move I make... so I can't even
compare the code. (But since both tables are too wide it doesn't matter.)
[And why is code so different...?]
I'd really appreciate some help (code below).
Lynn (not Lyn in thread).
OLD CODE
Selection.Tables(1).Select
With Selection.Tables(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.ColorIndex = wdAuto
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.ColorIndex = wdAuto
End With
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColorIndex = wdAuto
End With
Selection.Style = ActiveDocument.Styles("Tabelltext")
End Sub
NEW CODE
(I also tried to add second horizontal line visible)
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitWindow
With Selection.Tables(1)
If .Style <> "Tabellrutnät" Then
.Style = "Tabellrutnät"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.MoveUp Unit:=wdLine, Count:=3
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderTop)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("Tabelltext")
Selection.MoveRight Unit:=wdCharacter, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Tables(1).Columns(3).SetWidth ColumnWidth:=115.3, RulerStyle:= _
wdAdjustNone
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Tables(1).Rows.SetLeftIndent LeftIndent:=0.65, RulerStyle:= _
wdAdjustNone
With Selection.Tables(1)
.TopPadding = CentimetersToPoints(0)
.BottomPadding = CentimetersToPoints(0)
.LeftPadding = CentimetersToPoints(0.1)
.RightPadding = CentimetersToPoints(0.1)
.Spacing = 0
.AllowPageBreaks = True
.AllowAutoFit = True
End With
Selection.Tables(1).Rows.LeftIndent = CentimetersToPoints(0.1)
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=2
End Sub
format for theseses. In the template there are a few macros too. (I didn't
create them). One of them is a table format macro, working fine. (Copied from
the former template.)
Problem is (in former and in new template) that tables are too wide. The
left vertical line is too far out to the left (in the margin). (Since top and
bottom lines are visible they stick out...)
I've managed to record a macro of my own, same table format. While recording
the macro it seems like I manage to change the width, but when running the
macro it's too wide again. So probably I'm only changing that exact table,
and not the macro itself.
The code doesn't help me either. The old table macro is very simple, while
the one I make myself contains every single move I make... so I can't even
compare the code. (But since both tables are too wide it doesn't matter.)
[And why is code so different...?]
I'd really appreciate some help (code below).
Lynn (not Lyn in thread).
OLD CODE
Selection.Tables(1).Select
With Selection.Tables(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.ColorIndex = wdAuto
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.ColorIndex = wdAuto
End With
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColorIndex = wdAuto
End With
Selection.Style = ActiveDocument.Styles("Tabelltext")
End Sub
NEW CODE
(I also tried to add second horizontal line visible)
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=4, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitWindow
With Selection.Tables(1)
If .Style <> "Tabellrutnät" Then
.Style = "Tabellrutnät"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.MoveUp Unit:=wdLine, Count:=3
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorderTop)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("Tabelltext")
Selection.MoveRight Unit:=wdCharacter, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Tables(1).Columns(3).SetWidth ColumnWidth:=115.3, RulerStyle:= _
wdAdjustNone
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Tables(1).Rows.SetLeftIndent LeftIndent:=0.65, RulerStyle:= _
wdAdjustNone
With Selection.Tables(1)
.TopPadding = CentimetersToPoints(0)
.BottomPadding = CentimetersToPoints(0)
.LeftPadding = CentimetersToPoints(0.1)
.RightPadding = CentimetersToPoints(0.1)
.Spacing = 0
.AllowPageBreaks = True
.AllowAutoFit = True
End With
Selection.Tables(1).Rows.LeftIndent = CentimetersToPoints(0.1)
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=2
End Sub