Cell contents in a word doc

  • Thread starter Thread starter Kate P
  • Start date Start date
K

Kate P

Hi,

In Access, how do I open word docs in order to populate a table (in a db)
with the contents of specific cells, contained in a table in the word docs?

There would be multiple files, of same format, contained in a specific
folder. All docs in that folder will have the contents of specific cells put
into the db table - each doc = 1 record.

* I know how to reference the table & cells etc so skip that bit!

I am not new to programming but am a bit rusty, am new to VBA and never use
word.

Basically what I need is:
1. How to open a number of docs in a specific folder (one at a time)
2. Get the file name
2. Get access to the info inside them (in a general way - I'm assuming I can
set the value of a variable to = the contents of a cell & go from there)
3. Close the file, saving to a different folder.

And if possible:
4. Delete the file from the original location.

*** Don't need to see the word doc. Don't want to have to touch word. Or the
actual files either.
 
Use the Dir function to loop through the docs in the folder. Use wDoc.SaveAs
to save the file to another directory. This should get you started...

Dim wApp As New Word.Application
Dim wDoc As Word.Document
Dim wTbl As Word.Table
Dim wCell As Word.Cell
Dim strDocs As String
Dim strPath As String

strPath = "c:\temp\"

strDocs = Dir(strPath & "*.doc")

Do Until Len(strDocs) = 0

Set wDoc = wApp.Documents.Open(strPath & strDocs)

For Each wTbl In wDoc.Tables
For Each wCell In wTbl.Range.Cells
Debug.Print wCell.Range.Text
Next
Next

wDoc.Close
'move to the next doc
strDocs = Dir
Loop
 
Back
Top