473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

lots of Word tables to access Table?

Hello All,
I have about 700 word documents that have 2 tables one is static
4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100
what i wolud like to do is open the word doc.
import the first word table then import the second word table close
word doc
open next word doc and repeat process.
i am able to import one set of data currently into an excel spread
sheet
but how can i loop through all the documents and import them all into
one access table?
the below code works only on one doc and is designed for excell
my current code looks like this

Sub Listfiles()
'Open "F:\ACI-03-0760.DOC" For Input As #1
R = 1
Cells(R, 1) = "Quote Name"
Cells(R, 2) = "To"
Cells(R, 3) = "Contact"
Cells(R, 4) = "From"
Cells(R, 5) = "Fax"
Cells(R, 6) = "Date"
Cells(R, 7) = "sales Rep"
Range("a1:z1").Font.Bold = True
R = R + 1
Cells(R, 2) = (Documents(1).Tables(1).Rows(1).Cells(2)) 'customer name
Cells(R, 3) = (Documents(1).Tables(1).Rows(4).Cells(2)) 'customer
contact
Cells(R, 4) = (Documents(1).Tables(1).Rows(1).Cells(4)) 'from
Cells(R, 5) = (Documents(1).Tables(1).Rows(2).Cells(2)) 'fax number
Cells(R, 6) = (Documents(1).Tables(1).Rows(3).Cells(4)) ' date
Cells(R, 7) = (Documents(1).Tables(1).Rows(4).Cells(4)) ' Sales rep
R = R + 2
Cells(R, 2) = (Documents(1).Tables(2).Rows(2).Cells(1)) ' Item Number
Cells(R, 3) = (Documents(1).Tables(2).Rows(2).Cells(2)) ' Part number
Cells(R, 4) = (Documents(1).Tables(2).Rows(2).Cells(3)) ' Description
Cells(R, 5) = (Documents(1).Tables(2).Rows(2).Cells(4)) ' Qty
Cells(R, 6) = (Documents(1).Tables(2).Rows(2).Cells(5)) ' Price

All ideas are welcome
Phil

End Sub
Nov 12 '05 #1
3 4276
On 17 Oct 2003 16:27:42 -0700, ph*********@walter-speedmax.com.au
(Phil Rutter) wrote:

Use the Dir function to enumerate all documents in a certain folder.
Then call your function for each file:
Sub ListFiles(byval strFileName as String)
Open strFileName For Input As #1

MUCH better than opening a Word Document the way I described above is
to use Automation.
dim objWord as Word.Application
set objWord = New Word.Application
etc.
You now have access to the Word object model, and you can access Word
tables with little effort.

-Tom.

Hello All,
I have about 700 word documents that have 2 tables one is static
4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100
what i wolud like to do is open the word doc.
import the first word table then import the second word table close
word doc
open next word doc and repeat process.
i am able to import one set of data currently into an excel spread
sheet
but how can i loop through all the documents and import them all into
one access table?
the below code works only on one doc and is designed for excell
my current code looks like this

Sub Listfiles()
'Open "F:\ACI-03-0760.DOC" For Input As #1
R = 1
Cells(R, 1) = "Quote Name"
Cells(R, 2) = "To"
Cells(R, 3) = "Contact"
Cells(R, 4) = "From"
Cells(R, 5) = "Fax"
Cells(R, 6) = "Date"
Cells(R, 7) = "sales Rep"
Range("a1:z1").Font.Bold = True
R = R + 1
Cells(R, 2) = (Documents(1).Tables(1).Rows(1).Cells(2)) 'customer name
Cells(R, 3) = (Documents(1).Tables(1).Rows(4).Cells(2)) 'customer
contact
Cells(R, 4) = (Documents(1).Tables(1).Rows(1).Cells(4)) 'from
Cells(R, 5) = (Documents(1).Tables(1).Rows(2).Cells(2)) 'fax number
Cells(R, 6) = (Documents(1).Tables(1).Rows(3).Cells(4)) ' date
Cells(R, 7) = (Documents(1).Tables(1).Rows(4).Cells(4)) ' Sales rep
R = R + 2
Cells(R, 2) = (Documents(1).Tables(2).Rows(2).Cells(1)) ' Item Number
Cells(R, 3) = (Documents(1).Tables(2).Rows(2).Cells(2)) ' Part number
Cells(R, 4) = (Documents(1).Tables(2).Rows(2).Cells(3)) ' Description
Cells(R, 5) = (Documents(1).Tables(2).Rows(2).Cells(4)) ' Qty
Cells(R, 6) = (Documents(1).Tables(2).Rows(2).Cells(5)) ' Price

All ideas are welcome
Phil

End Sub


Nov 12 '05 #2
Phil,
If I'm reading this right, I think this is going to be somewhat
complicated. You can access the tables collection in your Word file
without a problem and even cycle through the rows and columns pretty
easily. I think the 4x5 table I would process somewhat as you have
described. Say you open a recordset based on an *Access* table (don't
want to get confused here!). Then you could add the 20 variables from
the Word doc to the single record in Access. (Or some to child
tables... whatever you need.) Then the second table, you could just
loop through by using rows and columns collections of the Word table
object.

That's the "inner" loop (for each individual document). Now the outer
loop. If all your documents are grouped in folders, you can use the
Dir function to get all the names and then process them. you could
use something like the OpenFile API at www.mvps.org to prompt the user
for a path and then just start processing. You'd want to throw up....
no wait, I mean *show* a custom message form, and show the filename
that's currently being processed. If processing all the files is
going to take a while, you don't want the user thinking that the
computer is frozen, giving it the three-finger salute and corrupting
all your files.

Instead of where you have Cells(R,C) here, you would be appending to
an Access recordset... say something like:

rs.Open "TableName",dbOpenDynamic '--just some type that allows adding
records
rs.AddNew

for intCell = 1 to 7
rs.Fields(intCell)=xlsFile.Cells(R,intCell)
next intCell

Then when you get the the fields you have to match manually, you could
use something like:

rs.Fields("TableFieldName") = xlsFile.Cells(R,C)

The one thing I'd worry about is how "normalized" your Word/Excel data
is. If rows are not records, then you're going to have to probably
convert them in memory somehow. Say you define an array(Row,Column),
you could just iterate through it by doing something like:

For MyColumn = 1 to Table.Rows.Count
For MyRow = 1 to Table.Columns.Count
'Process Here
Next MyRow
Next MyColumn

sorry, don't know off the top of my head if rows and columns in Word
tables are 1 or zero based. If zero-based, just subtract 1...

For MyColumn = 0 to Table.Rows.Count-1

Oh, and if you're going to throw in a loop that's going to repeat
several hundred times, you definitely want to log all the processing,
so at least you can query it and not have to read it all. When you
run your import process, I would move the processed files to a new
directory - DirectoryA if successful, DirectoryB if not successful.
Then at least you know at a glance if everything's working, and if
not, you can just move them all in bulk or point to the failed
folder... (BrowseFolder API at Accessweb comes to mind for that...)

Okay, enough rambling, but I hope this gets you started. Have fun!
Nov 12 '05 #3
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
Phil,
If I'm reading this right, I think this is going to be somewhat
complicated. You can access the tables collection in your Word file
without a problem and even cycle through the rows and columns pretty
easily. I think the 4x5 table I would process somewhat as you have
described. Say you open a recordset based on an *Access* table (don't
want to get confused here!). Then you could add the 20 variables from
the Word doc to the single record in Access. (Or some to child
tables... whatever you need.) Then the second table, you could just
loop through by using rows and columns collections of the Word table
object.

That's the "inner" loop (for each individual document). Now the outer
loop. If all your documents are grouped in folders, you can use the
Dir function to get all the names and then process them. you could
use something like the OpenFile API at www.mvps.org to prompt the user
for a path and then just start processing. You'd want to throw up....
no wait, I mean *show* a custom message form, and show the filename
that's currently being processed. If processing all the files is
going to take a while, you don't want the user thinking that the
computer is frozen, giving it the three-finger salute and corrupting
all your files.

Instead of where you have Cells(R,C) here, you would be appending to
an Access recordset... say something like:

rs.Open "TableName",dbOpenDynamic '--just some type that allows adding
records
rs.AddNew

for intCell = 1 to 7
rs.Fields(intCell)=xlsFile.Cells(R,intCell)
next intCell

Then when you get the the fields you have to match manually, you could
use something like:

rs.Fields("TableFieldName") = xlsFile.Cells(R,C

The one thing I'd worry about is how "normalized" your Word/Excel data
is. If rows are not records, then you're going to have to probably
convert them in memory somehow. Say you define an array(Row,Column),
you could just iterate through it by doing something like:

For MyColumn = 1 to Table.Rows.Count
For MyRow = 1 to Table.Columns.Count
'Process Here
Next MyRow
Next MyColumn

sorry, don't know off the top of my head if rows and columns in Word
tables are 1 or zero based. If zero-based, just subtract 1...

For MyColumn = 0 to Table.Rows.Count-1

Oh, and if you're going to throw in a loop that's going to repeat
several hundred times, you definitely want to log all the processing,
so at least you can query it and not have to read it all. When you
run your import process, I would move the processed files to a new
directory - DirectoryA if successful, DirectoryB if not successful.
Then at least you know at a glance if everything's working, and if
not, you can just move them all in bulk or point to the failed
folder... (BrowseFolder API at Accessweb comes to mind for that...)

Okay, enough rambling, but I hope this gets you started. Have fun!


Pieter,
thanks for all the information as i am pretty new to the coding thing
i tend to get myself lost.
thanks for the help.
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tom Dauria | last post by:
What I am trying to do is write a resume into a word document from information in an Access database. I have been using bookmarks and inserting table results into the document and so far it's...
41
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
4
by: svdh2 | last post by:
Dear All, I have lately strugled more and more with Access, what started as a simple database has brought me to the fundaments of Access. I need to transfer fields from various tables to a...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
14
by: awayne | last post by:
I am working with MS VB 6.5. I am putting together a MS Access (MS Access 2000) database for work to keep track of the projects and their status that we've done. I use MS Access to run a "Make-table...
2
by: Mo | last post by:
I am trying to produce an Access report which behaves like a two column table in Word. In other words each cell in column 1 contains a label and each cell in column 2 contains data from a...
3
by: Robertf987 | last post by:
Well, I think I've described what I want to do in the title here. In the database, I have two main tables that contain the main data for the database. One for group expenditures, another for...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.