Importing from Word

G

Guest

I have a table in Word saved as a .doc file. I need to import the file into
Access. Can this be done, and if so, how?

Thanks in advance.
 
P

pietlinden

I have a table in Word saved as a .doc file. I need to import the file into
Access. Can this be done, and if so, how?

Thanks in advance.

could you be more specific? do you want to split out the rows of the
Word table and write them somewhere, like to different fields in one
or more Access tables in your database? Or do you want to write the
table to a single record?

You can use the Tables collection of the Document object in Word, and
then loop through the Rows and Columns collections... but before going
through that, it would help if you explained further what you need to
do specifically.
 
P

pietlinden

Okay, my turn to feel dumb... Maybe I should cross post this in the
Word programming NG...

I can get the contents of multiple columns and write them to an Access
table without a problem, BUT I get two unreadable characters at the
end of the text, which I'm not sure how to get rid of...

and this REALLY needs error handling...

Public Sub GetTableFromWord(ByVal strDoc As String, Optional ByVal
intTableNo As Integer = 1)
' Sample Call (watch the wrap... should be one line):
'GetTableFromWord "C:\Documents and Settings\Pieter\My Documents
\Application Support Specialist Gaylord Entertainment.doc"

'---Access Variables
Dim r As DAO.Recordset

'---Word Variables
Dim appWord As Word.Application
Dim docWord As Word.Document
Dim tbl As Word.Table
Dim docRow As Word.Row

'---create the append-only recordset to write to the Access Table
"tblWordDoc"
Set r = DBEngine(0)(0).OpenRecordset("tblWordDoc", dbOpenTable,
dbAppendOnly)

'---open Word... I should really use fIsAppRunning() from Access
Web... shame on me!
Set appWord = New Word.Application

appWord.Documents.Open strDoc
appWord.Documents(strDoc).Activate

Set docWord = appWord.ActiveDocument

Set tbl = ActiveDocument.Tables(intTableNo)
For Each docRow In tbl.Rows
Debug.Print docRow.Cells(1).Range
r.AddNew
r.Fields("ColumnA") = docRow.Cells(1).Range.Text
r.Fields("ColumnB") = docRow.Cells(2).Range.Text
r.Update
Next docRow

r.Close
Set r = Nothing
Set tbl = Nothing
docWord.Close
Set docWord = Nothing
appWord.Quit
Set appWord = Nothing

'open the table so I can see the new records. Bad to do in a real
DB, but this is a test.
DoCmd.OpenTable "tblWordDoc"
End Sub

Can this be done with ADO? I know you can send data using ADO, like in
Developer's Handbook, but what about reading using some ADO object,
like a textstream? (Watch me hijack the thread;... I really ought to
start a new one!)

Thanks,

Pieter
 
J

John Nurick

Hi Landman,

It's a long time since I've had to do it, but try this:

1) Make sure that the table has a regular structure (same number of
cells in every row, no merged cells, no nested tables...).

2) Use Save As to save the .doc file to HTML.

3) Use Access to import the table from HTML.
 
P

pietlinden

Hi Landman,

It's a long time since I've had to do it, but try this:

1) Make sure that the table has a regular structure (same number of
cells in every row, no merged cells, no nested tables...).

2) Use Save As to save the .doc file to HTML.

3) Use Access to import the table from HTML.

Wait! That's so easy it HAS to be cheating!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top