AW: zahlen aus excel in wordtabelle farbig einfügen
27.09.2011 15:29:42
fcs
Hallo Preusbep,
hier mal ein entsprechendes in Word erstelltes Makro. Mit Wordobjekten statt mit Select.
Einige excelspezifische Zeilen in deinem Code hab ich hier auskommentiert.
Gruß
Franz
'Erstellt unter Word 2003
Sub Makro2()
' Formatierung Text in Word-Zellen
Dim Farbe(1 To 3, 1 To 1) As Long, i As Integer
'Wordobjekte
Dim objWdTab As Word.Table, objWdZelle As Word.Cell, objWdDoc As Word.Document
' Dim objWdTab As Object, objWdZelle As Object, objWdDoc As Object
' Set Word = CreateObject("word.Application")
Word.Application.Visible = True
' Word.Documents.Open FileName:="C:\...\Dok1.doc"
Set objWdDoc = Word.ActiveDocument
Set objWdTab = objWdDoc.Tables(1)
'For i = 1 To 3
'Farbe(i, 1) = Worksheets("Tabelle1").Cells(1 + i, 2)
'Next
Farbe(1, 1) = 255 'wdColorRed
Farbe(2, 1) = 16711680 'wdColorBlue
Farbe(3, 1) = 65280 'wdColorBrightGreen
'In Excel
'For i = 1 To 3
'Cells(i + 9, 2) = Farbe(i, 1)
'Next i
For i = 1 To 3
Set objWdZelle = objWdTab.Cell(i, 1)
With objWdZelle
'Vertikale Ausrichtung in Zelle
.VerticalAlignment = 1 'wdCellAlignVerticalCenter
With .Range
'Textausrichtung in Zelle
.ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter
'Schriftfarbe in Zelle
.Font.Color = Farbe(i, 1)
'Textinhalt in der Zelle eintragen
.Text = Farbe(i, 1)
End With
End With
Next i
End Sub