Um Excel von Word aus aufzurufen mußt Du über
Extras->Verweise
einen Verweis auf Excel setzen: CheckBox vor "Microsoft Excel 11.0 Object Library" setzen (O2003).
Ansonsten habe ich unter O2003 eben diesen Code ausgeführt: Keine Probleme!
Option Explicit
Sub Word_nach_Excel()
Dim xlApp As Excel.Application
Dim xlWkb As Excel.Workbook
Dim xlWks As Excel.Worksheet
Dim oDoc As Document
Dim lngFreieZeile As Long
Dim xlOffen As Boolean
On Error Resume Next
xlOffen = True
Set oDoc = ActiveDocument
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
Set xlApp = CreateObject("Excel.Application"): DoEvents
xlApp.Visible = True
xlOffen = False
End If
Set xlWkb = xlApp.Workbooks.Open("C:\test.xls")
Set xlWks = xlWkb.Worksheets(1)
With xlWks
lngFreieZeile = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row + 1
.Cells(lngFreieZeile, 1) = oDoc.Bookmarks("Text1").Range.Text
.Cells(lngFreieZeile, 2) = oDoc.FormFields("Dropdown1").Result
If oDoc.FormFields("Kontrollkästchen1").CheckBox.Value = True Then
.Cells(lngFreieZeile, 3) = "ja"
ElseIf oDoc.FormFields("Kontrollkästchen1").CheckBox.Value = False Then
.Cells(lngFreieZeile, 3) = "nein"
End If
If Err.Number = 0 Then
MsgBox "Alle Eingabefelder erfolgreich übertragen.", vbInformation, "Info..."
Else
Err.Clear
MsgBox "Nicht alle Eingabefelder übertragen!", vbCritical, "Fehler..."
End If
End With
xlWkb.Close True
Set xlWks = Nothing
Set xlWkb = Nothing
If xlOffen = False Then xlApp.Quit
Set xlApp = Nothing
Set oDoc = Nothing
End Sub
Bitte sicherheitshalber prüfen, ob die Steuerelemente auch die Namen haben, die im Code verwendet werden und ob es tatsächlich Formular Steuerelemente sind.
Severus
|