VBA Excel TabStops in Word
06.05.2018 19:51:48
Karl
Ich erstelle aus Excel heraus eine Word-Datei ... dabei werden TabStops definiert, jedoch kann ich diese nicht rechtsbündig ausrichten, obwohl folgende Zeile dies eigentlich machen sollte.
.ParagraphFormat.TabStops.Add Position:=350, Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
Programmbeispiel:
Sub Test001()
Dim wdApp As Object
Dim wdoc As Object
Dim ab As Byte
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
On Error GoTo 0
If wdApp Is Nothing Then
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
End If
wdApp.Documents.Add
Set wdoc = wdApp.ActiveDocument
wdoc.Range.Font.Name = "Arial"
wdoc.Range.Font.Size = 9
wdoc.Range.Font.Bold = True
With wdoc.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = 40
.BottomMargin = 30
.LeftMargin = 50
.RightMargin = 20
.HeaderDistance = 15
.FooterDistance = 15
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
With wdApp.Selection
'Tabstops definieren
.ParagraphFormat.TabStops.Add Position:=0, Alignment:=wdAlignTabLeft, Leader:= _
wdTabLeaderSpaces
.ParagraphFormat.TabStops.Add Position:=50, Alignment:=wdAlignTabLeft, Leader:= _
wdTabLeaderSpaces
.ParagraphFormat.TabStops.Add Position:=100, Alignment:=wdAlignTabLeft, Leader:= _
wdTabLeaderSpaces
.ParagraphFormat.TabStops.Add Position:=350, Alignment:=wdAlignTabRight, Leader:= _
wdTabLeaderSpaces
.ParagraphFormat.TabStops.Add Position:=420, Alignment:=wdAlignTabRight, Leader:= _
wdTabLeaderSpaces
'Rechnungstext "Für die erhaltenen ..."
.Font.Color = RGB(0, 0, 0)
.Font.Name = "Arial"
.Font.Bold = False
.Font.Size = 8
.TypeParagraph 'Zeilenschaltung
.TypeParagraph 'Zeilenschaltung
'Rechnungsdatum
.TypeText Text:=vbTab
.TypeText Text:=vbTab
.TypeText Text:=vbTab
.TypeText Text:=CStr("Hallo")
.TypeParagraph 'Zeilenschaltung
End With
Set wdoc = Nothing 'Objekt freigeben
Set wdApp = Nothing 'Objekt freigeben
End Sub