Supportnet Computer
Planet of Tech

Supportnet / Forum / Textverarbeitung

Word Makro alle Tabellen Spaltenbreite vorgeben





Frage

Hallo, ich habe einige Tabellen in Word die alle gleich formatiert werden sollen (breite spalte a = 3cm, spalte b = 1,13cm, usw..). Jetzt habe ich es schon geschafft, ein Makro zu machen, das mir das mit der Tabelle macht die ich makiert habe. Mit folgendem VB-Code Sub Tabelle() ' ' Tabelle Makro ' Makro aufgezeichnet am 21.10.2008 von fWagner ' With Selection.Tables(1) .TopPadding = CentimetersToPoints(0.08) .BottomPadding = CentimetersToPoints(0.08) .LeftPadding = CentimetersToPoints(0.08) .RightPadding = CentimetersToPoints(0.08) .Spacing = CentimetersToPoints(0) .AllowPageBreaks = True .AllowAutoFit = False End With Selection.Tables(1).Columns(1).PreferredWidthType = wdPreferredWidthPoints Selection.Tables(1).Columns(1).PreferredWidth = CentimetersToPoints(3) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(1.13) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(1.26) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(5.83) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(2.22) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(8.25) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(4.13) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(2.19) End Sub Meine Versuche mit DIMTable sind gescheitert, allderings kenne ich mich da auch nicht aus. Ich habe es mal hiermit versucht, funktioniert aber nicht: Sub test3() ' ' test3 Makro ' Makro aufgezeichnet am 22.10.2008 von fWagner ' Dim Tabelle As Table For Each Tabelle In ActiveDocument.Tables Tabelle.Columns(1).PreferredWidthType = wdPreferredWidthPoints Tabelle.Columns(1).PreferredWidth = CentimetersToPoints(3) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(1.13) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(1.26) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(5.83) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(2.22) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(8.25) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(4.13) Selection.Move Unit:=wdColumn, Count:=1 Selection.SelectColumn Selection.Columns.PreferredWidthType = wdPreferredWidthPoints Selection.Columns.PreferredWidth = CentimetersToPoints(2.19) Next Tabelle End Sub Kann mir jemand sagen, was ich falsch gemacht habe und wies Weiter geht, finde in allen Foren keine Antworten oder verstehe sie nicht. Vielen Dank schonmal

Antwort 1 von Lisa2004

Sub Tabelle()
Dim Tabelle As Word.Table
For Each Tabelle In ActiveDocument.Tables

    Tabelle.Columns(1).Width = CentimetersToPoints(3)
    Tabelle.Columns(2).Width = CentimetersToPoints(1.13)
    Tabelle.Columns(3).Width = CentimetersToPoints(1.26)
    Tabelle.Columns(4).Width = CentimetersToPoints(5.83)
    
    Tabelle.Columns(5).Width = CentimetersToPoints(2.22)
    Tabelle.Columns(6).Width = CentimetersToPoints(8.25)
    Tabelle.Columns(7).Width = CentimetersToPoints(4.13)
    Tabelle.Columns(8).Width = CentimetersToPoints(2.19)
    Next Tabelle

End Sub

wird das nicht zu breit? -dann anpassen.
Gruß Lisa