AW: Excel Tabelle in Word exportieren
04.12.2004 22:30:03
Roger
Hallo Volker
Hab da mal was ähnliches gemacht. Probiers mal aus eventuell musst du den code entsprechend anpassen. Ich hab da die Namen der Tabellenblätter in einer Listbox von dort wähle ich aus welches Blatt ich will, markiere es und drücke dann den Button.
Gruss Roger
Private Sub CommandButton1_Click()
Dim WordObj As Object
Dim Bereich As Variant
Dim WordDoc As Object
Dim ExTab As Object
Dim i As Integer
Dim x As Integer
Dim y As Integer
Dim arrWks()
Dim iCounter As Integer, iCount As Integer
For iCounter = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(iCounter) Then
Worksheets(ListBox1.List(iCounter)).Activate
End If
Next iCounter
i = ActiveSheet.UsedRange.Rows.Count + 1
Bereich = Range("A6:C" & i).Value
On Error Resume Next
Set WordObj = GetObject(, "word.application.10")
If Err.Number = 429 Then
Set WordObj = CreateObject("word.application.10")
Err.Number = 0
End If
WordObj.Visible = True
Set WordDoc = WordObj.Documents.Add
Set ExTab = WordDoc.Tables.Add _
(WordObj.Selection.Range, UBound(Bereich, 1), UBound(Bereich, 2))
With ExTab
For x = 1 To UBound(Bereich, 1)
For y = 1 To UBound(Bereich, 2)
.Cell(x, y).Range.InsertAfter Bereich(x, y)
Next y
Next x
End With
Set WordObj = Nothing
Set WordDoc = Nothing
Set ExTab = Nothing
Worksheets("Hilfsblatt").Activate
End Sub