Hallo zusammen
Ich arbeite mit Office 97. In einem
Verzeichnis liegen eine beliebige Anzahl
Wordformulare, die alle gleich aufgebaut
sind.
Aus Access soll nun von jedem
Word-Formular bestimmte Daten rausgelesen
und in einer Tabelle abgelegt werden.
Frage: Wie kann ich aus Access direkt auf
ein bestimmtes Feld eines Word-Docs
zugreifen und ist das überhaupt eine gute
Lösung (Stichwort Performance).
Das geht recht einfach (aber langsam) per OLE-Automation, z.B. so:
Private Function LeseWord()
Const wdGoToBookmark = -1, wdWord = 2, wdExtend = 1
Const Path = "I:\Samples\"
Dim Tmp, WordObj As Object, I As Long
On Error Resume Next
Tmp = ""
Set WordObj = GetObject(, "Word.Application")
If Err.Number 0 Then Set WordObj = CreateObject("Word.Application")
On Error GoTo 0
' WordObj.Application.Visible = True
For I = 1 To 3
WordObj.Documents.Open FileName:=Path & "Test" & I & ".Doc", ReadOnly:=True
With WordObj.Selection
.Goto What:=wdGoToBookmark, name:="KundenNr"
.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Tmp = Tmp & .Text & vbCrLf
End With
WordObj.Documents.Close
Next I
Set WordObj = Nothing
LeseWord = Tmp
End Function
Reinhard