Import Fields from Word Table into access record

  • Thread starter Thread starter Gordzilla
  • Start date Start date
G

Gordzilla

I have a Word document that consists of one table. Each cell in the table
contains a field in the row of my access table.
How can I code Access to Open the Word file, process the table one cell at a
time extracting the data (some may be blank) and add a new record to the
access table and enter the retrieved values?

The Word document is basically an entry form. Saving the file as text and
importing is not an option as the Word file is protected.

I would like the user to either browse to the Word file or if possible drag
and drop the Word File onto a Control

Any suggestions?
 
Public Function ImportTable() As Boolean
Dim tbl As Word.Table
Dim wrdapp As Word.Application
Dim wrddoc As Word.Document
Dim FileToOpen As String
Dim rowscnt As Long
Dim cellcnt As Long
Dim sht As Worksheet
Dim jval As Long, jcells As Long, j As Long, k As Long

'
' Ask for the Word Document that has the table in it
'
FileToOpen = Application.GetOpenFilename("Word Documents (*.doc)
*.doc")
Set wrdapp = CreateObject("Word.Application")

' Open the document and the table

Set wrddoc = wrdapp.Documents.Open(FileToOpen)
Set tbl = wrddoc.Tables(1)
jval = tbl.Rows.Count
For j = 1 To jval
jcells = tbl.Rows(j).Cells.Count
For k = 1 To jcells
Cells(j, k) = GetRidOfCRLF(tbl.Rows(j).Cells(k).Range.Text)
Next k
Next j

Stop
wrddoc.Close
End Function


Here is some code that imports from a table in word to an Exce
spreadsheet. The code should work the same in Access except that yo
need to insert table fields for cells.

GetRidOfCRLF strips out extraneous characters like Carriage Return an
Linefeed
 
Back
Top