Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

READING A WORD DOCUMENT ONE LINE AT THE TIME FROM WITHIN ACCESS 1

Status
Not open for further replies.

HLEE1167

Programmer
Mar 21, 2006
17
US
I need to be able to read a Word document from within Access using VBA. How could I read one line of text to populate an Access Variable?

Thank you
 
A starting point:
Dim oDoc As Object, oPara As Object
Set oDoc = GetObject("\path\to\document.doc")
For Each oPara In oDoc.Paragraphs
Debug.Print oPara.Range.Text
Next
oDoc.Close False
Set oDoc = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Not sure if this one works with word documents, I beleive the main code is one PHV post's... But it reads one line at a time.

But I use a select case statement.

Partial Code...
Code:
Const ForReading = 1
Dim FSO As Object, TF As Object, arr
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set TF = FSO.OpenTextFile("\path\to\file.txt", ForReading)
Set TF = FSO.OpenTextFile(strFilePath, ForReading)
arr = Split(TF.ReadAll, vbCrLf)
TF.Close
For i = 0 To UBound(arr) - 1
' do stuff with arr(i)
Select Case i  'Line Number
Case 24   'Assign First & Last Name
  x = InStr(1, arr(i), strSpace)
  y = Mid(arr(i), 1, x)
    ContactFirstName.Value = y
  x = InStrRev(arr(i), strSpace)
  y = Right(arr(i), x)
  ContactLastName.Value = y
Case 25    'Assign Address
  BillingAddress.Value = Trim(arr(i))

Case 26 'Assign City, State & Postal Code
  ...
  ...
End Select
Next

Hope this helps....


AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Thank you both for the help. I used the technique from PHV and work very nicely.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top