Getting a line from another document

E

Ema

How could I retrieve the first line of another document
that is not open? I'd prefer it if this document does not
open up at all if possible, but whatever way works, works
for me.
Thanks!
 
H

Helmut Weber

Hi Ema,
think there is no simple way of getting the first
line from a word(!)-document, without using word.
Anyway, the following is an easy going working
solution.
Sub Word2()
Dim w2 As Word.Application
Set w2 = New Word.Application
With w2
.Visible = False
.Documents.Open "c:\test.doc"
.Selection.WholeStory
.Selection.Collapse
.Selection.ExtendMode = True
.Selection.EndKey unit:=wdLine
.Selection.Copy
.Documents(1).Saved = True
.Documents(1).Close
.Quit
End With
Set w2 = Nothing
Selection.Paste
End Sub
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
H

Helmut Weber

Hi Ema,
how about that (XP-Version):
Sub InvisibleDoc()
Dim aDoc As Document
Set aDoc = Documents.Open("c:\test.doc", Visible:=False)
With aDoc
.Activate
With Selection
.WholeStory
.Collapse
.ExtendMode = True
.EndKey unit:=wdLine
.Copy
End With
..Close
End With
Selection.Paste
End Sub
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word XP, NT 4.0
 
Top