AW: Word Dokument in Excel einlesen
11.08.2008 17:36:37
Tino
Hallo,
hier mal ein Beispiel.
Um aber Deinen Text raus zu filtern, muss man deine Worddatei besser kennen.
!!! benötigt den Verweis Microsoft Word 11.0 Object Library !!!
(kann auch 10.0 oder so sein, ist Versionsabhängig)
Option Explicit
Sub WordNachExcel()
Dim objWordApp As New Word.Application
Dim objWordDok As Word.Document
Dim Pfad As String, strFile As String
Dim varText As Variant
On Error GoTo Fehler:
Application.ScreenUpdating = False
Pfad = _
IIf(Right$(ThisWorkbook.Path, 1) = "\", ThisWorkbook.Path, ThisWorkbook.Path & "\")
Set objWordApp = CreateObject("Word.Application")
objWordApp.Application.ScreenUpdating = False
objWordApp.Visible = False 'True zum ausblenden
strFile = Dir(Pfad & "\*.doc")
Do While strFile "" 'Schleife bis keine Word mehr da
'Datei öffnen
Set objWordDok = objWordApp.Documents.Open(Pfad & strFile)
With objWordApp
'Text markieren
.Selection.WholeStory
'markierung in Veriable
varText = .Selection
'***hier muss der Text zerlegt werden um ihn in die Zellen zu schreiben
'ist nur ein Beispiel!!!!
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = varText
End With
'Word wieder schließen
objWordDok.Close False
'Objektvar. wieder freigeben
Set objWordDok = Nothing
'nächstes Worddoc.
strFile = Dir
Loop
objWordApp.Application.ScreenUpdating = True
objWordApp.Quit
If Not objWordDok Is Nothing Then Set objWordDok = Nothing
If Not objWordApp Is Nothing Then Set objWordApp = Nothing
Application.ScreenUpdating = True
Exit Sub
Fehler:
On Error Resume Next
objWordDok.Close False
objWordApp.Quit
If Not objWordDok Is Nothing Then Set objWordDok = Nothing
If Not objWordApp Is Nothing Then Set objWordApp = Nothing
On Error GoTo 0
Application.ScreenUpdating = True
MsgBox "Fehler!", vbCritical
End Sub
Gruß Tino
www.VBA-Excel.de