Word Table to Access | | |
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 is one row containing picture(s) as well.
So far, what I did is doing it manually for each word docs I have.
Select Table
Convert Table to Text(I use ^ character for delimiter)
Save it to a text file(with char substitution, and CR/LF)
Then, Load them to Access DB.
Is there an easier way to do this? | | | | re: Word Table to Access
I'd love to see it done easily in windows. What you can do is to save your
word doc to text with delimiter and let perl handle the parsing.
Opensource to the rescue!
"Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...[color=blue]
> Hi, I was wondering if expert can give me some lite to convert my word[/color]
table[color=blue]
> into access database.
>
> Note: within each cell of my word table(s), some has multi-line data in[/color]
it.[color=blue]
> In addition, there is one row containing picture(s) as well.
>
> So far, what I did is doing it manually for each word docs I have.
>
> Select Table
> Convert Table to Text(I use ^ character for delimiter)
> Save it to a text file(with char substitution, and CR/LF)
> Then, Load them to Access DB.
>
> Is there an easier way to do this?
>
>[/color] | | | | re: Word Table to Access
Hi Ruby,
The easiest way to do this is to copy the table to Excel, then either
save the Excel workbook and import it into Access or copy/paste from
Excel to Access.
--
Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.
~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP
Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
"Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...[color=blue]
> Hi, I was wondering if expert can give me some lite to convert my[/color]
word table[color=blue]
> into access database.
>
> Note: within each cell of my word table(s), some has multi-line[/color]
data in it.[color=blue]
> In addition, there is one row containing picture(s) as well.
>
> So far, what I did is doing it manually for each word docs I have.
>
> Select Table
> Convert Table to Text(I use ^ character for delimiter)
> Save it to a text file(with char substitution, and CR/LF)
> Then, Load them to Access DB.
>
> Is there an easier way to do this?
>
>[/color] | | | | re: Word Table to Access
I think the only way to do this project is manually. www.klh-tech.com
KLH Technology Solutions | | | | re: Word Table to Access
I tried that venue but no go. The problem is with the multi-line data. Excel
treat each line as a new row. I figure that Excel does not understant CR/LF
character. Perhap you can cheat that but how? Thanks
"Beth Melton" <bmelton@NoSpam4Memvps.org> wrote in message
news:uBHsC5k9DHA.1636@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi Ruby,
>
> The easiest way to do this is to copy the table to Excel, then either
> save the Excel workbook and import it into Access or copy/paste from
> Excel to Access.
>
> --
> Please post all follow-up questions to the newsgroup. Requests for
> assistance by email can not be acknowledged.
>
> ~~~~~~~~~~~~~~~
> Beth Melton
> Microsoft Office MVP
>
> Word FAQ: http://mvps.org/word
> TechTrax eZine: http://mousetrax.com/techtrax/
> MVP FAQ site: http://mvps.org/
>
>
> "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...[color=green]
> > Hi, I was wondering if expert can give me some lite to convert my[/color]
> word table[color=green]
> > into access database.
> >
> > Note: within each cell of my word table(s), some has multi-line[/color]
> data in it.[color=green]
> > In addition, there is one row containing picture(s) as well.
> >
> > So far, what I did is doing it manually for each word docs I have.
> >
> > Select Table
> > Convert Table to Text(I use ^ character for delimiter)
> > Save it to a text file(with char substitution, and CR/LF)
> > Then, Load them to Access DB.
> >
> > Is there an easier way to do this?
> >
> >[/color]
>
>[/color] | | | | re: Word Table to Access
"Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...[color=blue]
> Hi, I was wondering if expert can give me some lite to convert my word[/color]
table[color=blue]
> into access database.
>
> Note: within each cell of my word table(s), some has multi-line data in[/color]
it.[color=blue]
> In addition, there is one row containing picture(s) as well.
>
> So far, what I did is doing it manually for each word docs I have.
>
> Select Table
> Convert Table to Text(I use ^ character for delimiter)
> Save it to a text file(with char substitution, and CR/LF)
> Then, Load them to Access DB.
>
> Is there an easier way to do this?[/color]
If you want to write code to do it, here is an example that just creates a
message box for each cell in the table showing the value. This could be
converted to create a record in Access and you could adapt it to do this for
a number of documents, each with 1 or more tables.
Is this a route you might pursue?
Private Sub cmdExtract_Click()
On Error GoTo Err_Handler
Dim strPath As String
Dim strValue As String
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim wdTbl As Object 'Word.Table
Dim wdRow As Object 'Word.Row
Dim wdCol As Object 'Word.Column
Dim wdCell As Object 'Word.Cell
strPath = "C:\Example.doc"
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(strPath)
If wdDoc.Tables.Count > 0 Then
Set wdTbl = wdDoc.Tables(1)
For Each wdRow In wdTbl.Rows
For Each wdCol In wdTbl.Columns
strValue = wdTbl.Cell(wdRow.Index, wdCol.Index).Range.Text
If Len(strValue) > 2 Then
strValue = Left$(strValue, Len(strValue) - 2)
Else
strValue = ""
End If
MsgBox strValue
Next wdCol
Next wdRow
End If
MsgBox "Done", vbInformation
Exit_Handler:
On Error Resume Next
If Not wdDoc Is Nothing Then
wdDoc.Close
Set wdDoc = Nothing
End If
If Not wdApp Is Nothing Then
wdApp.Quit
Set wdApp = Nothing
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub | | | | re: Word Table to Access
You could use Find/Replace in Word table:
Find: ^p
Replace: @@@ (or a character you are not using)
In Excel use Find/Replace:
Find: @@@
Replace: press <Alt 010> (Use the 10-key pad for this. Note that you
will not see anything)
Note that you may need to restart Excel to clear the search string in
the Replace text box.
--
Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.
~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP
Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
"Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
news:c10d00$1bs5h1$1@ID-205437.news.uni-berlin.de...[color=blue]
> I tried that venue but no go. The problem is with the multi-line[/color]
data. Excel[color=blue]
> treat each line as a new row. I figure that Excel does not[/color]
understant CR/LF[color=blue]
> character. Perhap you can cheat that but how? Thanks
>
> "Beth Melton" <bmelton@NoSpam4Memvps.org> wrote in message
> news:uBHsC5k9DHA.1636@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hi Ruby,
> >
> > The easiest way to do this is to copy the table to Excel, then[/color][/color]
either[color=blue][color=green]
> > save the Excel workbook and import it into Access or copy/paste[/color][/color]
from[color=blue][color=green]
> > Excel to Access.
> >
> > --
> > Please post all follow-up questions to the newsgroup. Requests for
> > assistance by email can not be acknowledged.
> >
> > ~~~~~~~~~~~~~~~
> > Beth Melton
> > Microsoft Office MVP
> >
> > Word FAQ: http://mvps.org/word
> > TechTrax eZine: http://mousetrax.com/techtrax/
> > MVP FAQ site: http://mvps.org/
> >
> >
> > "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> > news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...[color=darkred]
> > > Hi, I was wondering if expert can give me some lite to convert[/color][/color][/color]
my[color=blue][color=green]
> > word table[color=darkred]
> > > into access database.
> > >
> > > Note: within each cell of my word table(s), some has multi-line[/color]
> > data in it.[color=darkred]
> > > In addition, there is one row containing picture(s) as well.
> > >
> > > So far, what I did is doing it manually for each word docs I[/color][/color][/color]
have.[color=blue][color=green][color=darkred]
> > >
> > > Select Table
> > > Convert Table to Text(I use ^ character for delimiter)
> > > Save it to a text file(with char substitution, and CR/LF)
> > > Then, Load them to Access DB.
> > >
> > > Is there an easier way to do this?
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] | | | | re: Word Table to Access
"Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message news:<c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de>...[color=blue]
> 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 is one row containing picture(s) as well.
>
> So far, what I did is doing it manually for each word docs I have.
>
> Select Table
> Convert Table to Text(I use ^ character for delimiter)
> Save it to a text file(with char substitution, and CR/LF)
> Then, Load them to Access DB.
>
> Is there an easier way to do this?[/color]
Don't think so, unless you use code to do the conversions and then
imports for you. If they're all in the same directory, you could use
the Dir function to loop through the contents of the directory,
process the Word file to create the importable file, and then after
those are done, import them into Access... but that's all I can think
of. | | | | re: Word Table to Access
Can I do it programatically? I have about 100 word files with at least 3
tables inside them.
I don't know if the following is possible. Since we can save those word docs
into an html documents, can we parse the html docs and extract the data?
They are pretty structured <table>... <tr>...<td> ... </td>..</tr>...<table>
and some other formatting tags such as <b></b> etc...
Wish there are tools to do that.
Thanks
"Beth Melton" <bmelton@NoSpam4Memvps.org> wrote in message
news:O1$fAWm9DHA.1948@TK2MSFTNGP12.phx.gbl...[color=blue]
> You could use Find/Replace in Word table:
>
> Find: ^p
> Replace: @@@ (or a character you are not using)
>
> In Excel use Find/Replace:
>
> Find: @@@
> Replace: press <Alt 010> (Use the 10-key pad for this. Note that you
> will not see anything)
>
> Note that you may need to restart Excel to clear the search string in
> the Replace text box.
>
> --
> Please post all follow-up questions to the newsgroup. Requests for
> assistance by email can not be acknowledged.
>
> ~~~~~~~~~~~~~~~
> Beth Melton
> Microsoft Office MVP
>
> Word FAQ: http://mvps.org/word
> TechTrax eZine: http://mousetrax.com/techtrax/
> MVP FAQ site: http://mvps.org/
>
>
> "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> news:c10d00$1bs5h1$1@ID-205437.news.uni-berlin.de...[color=green]
> > I tried that venue but no go. The problem is with the multi-line[/color]
> data. Excel[color=green]
> > treat each line as a new row. I figure that Excel does not[/color]
> understant CR/LF[color=green]
> > character. Perhap you can cheat that but how? Thanks
> >
> > "Beth Melton" <bmelton@NoSpam4Memvps.org> wrote in message
> > news:uBHsC5k9DHA.1636@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Hi Ruby,
> > >
> > > The easiest way to do this is to copy the table to Excel, then[/color][/color]
> either[color=green][color=darkred]
> > > save the Excel workbook and import it into Access or copy/paste[/color][/color]
> from[color=green][color=darkred]
> > > Excel to Access.
> > >
> > > --
> > > Please post all follow-up questions to the newsgroup. Requests for
> > > assistance by email can not be acknowledged.
> > >
> > > ~~~~~~~~~~~~~~~
> > > Beth Melton
> > > Microsoft Office MVP
> > >
> > > Word FAQ: http://mvps.org/word
> > > TechTrax eZine: http://mousetrax.com/techtrax/
> > > MVP FAQ site: http://mvps.org/
> > >
> > >
> > > "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> > > news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...
> > > > Hi, I was wondering if expert can give me some lite to convert[/color][/color]
> my[color=green][color=darkred]
> > > word table
> > > > into access database.
> > > >
> > > > Note: within each cell of my word table(s), some has multi-line
> > > data in it.
> > > > In addition, there is one row containing picture(s) as well.
> > > >
> > > > So far, what I did is doing it manually for each word docs I[/color][/color]
> have.[color=green][color=darkred]
> > > >
> > > > Select Table
> > > > Convert Table to Text(I use ^ character for delimiter)
> > > > Save it to a text file(with char substitution, and CR/LF)
> > > > Then, Load them to Access DB.
> > > >
> > > > Is there an easier way to do this?
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] | | | | re: Word Table to Access
Thanks Fletcher.
I might be able to follow your VBscript(is it? or is it a VB program that
need to be compiled?) program but will this program work for multi-line
cells? As I mentioned in my earlier message, I can't directly cut-and-paste
the table into the excel sheet cause excel treat each line of the multi-line
cell as another row of data. Somehow excel do not know how to handle cell
data with CR/LF character in it. Can we escape them?
Thanks again
"Fletcher Arnold" <fletch@home.com> wrote in message
news:c10eop$nsv$1@hercules.btinternet.com...[color=blue]
> "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...[color=green]
> > Hi, I was wondering if expert can give me some lite to convert my word[/color]
> table[color=green]
> > into access database.
> >
> > Note: within each cell of my word table(s), some has multi-line data in[/color]
> it.[color=green]
> > In addition, there is one row containing picture(s) as well.
> >
> > So far, what I did is doing it manually for each word docs I have.
> >
> > Select Table
> > Convert Table to Text(I use ^ character for delimiter)
> > Save it to a text file(with char substitution, and CR/LF)
> > Then, Load them to Access DB.
> >
> > Is there an easier way to do this?[/color]
>
>
> If you want to write code to do it, here is an example that just creates a
> message box for each cell in the table showing the value. This could be
> converted to create a record in Access and you could adapt it to do this[/color]
for[color=blue]
> a number of documents, each with 1 or more tables.
> Is this a route you might pursue?
>
>
> Private Sub cmdExtract_Click()
>
> On Error GoTo Err_Handler
>
> Dim strPath As String
> Dim strValue As String
> Dim wdApp As Object 'Word.Application
> Dim wdDoc As Object 'Word.Document
> Dim wdTbl As Object 'Word.Table
> Dim wdRow As Object 'Word.Row
> Dim wdCol As Object 'Word.Column
> Dim wdCell As Object 'Word.Cell
>
> strPath = "C:\Example.doc"
>
> Set wdApp = CreateObject("Word.Application")
>
> Set wdDoc = wdApp.Documents.Open(strPath)
>
> If wdDoc.Tables.Count > 0 Then
>
> Set wdTbl = wdDoc.Tables(1)
>
> For Each wdRow In wdTbl.Rows
>
> For Each wdCol In wdTbl.Columns
>
> strValue = wdTbl.Cell(wdRow.Index, wdCol.Index).Range.Text
>
> If Len(strValue) > 2 Then
> strValue = Left$(strValue, Len(strValue) - 2)
> Else
> strValue = ""
> End If
>
> MsgBox strValue
>
> Next wdCol
>
> Next wdRow
>
> End If
>
> MsgBox "Done", vbInformation
>
> Exit_Handler:
>
> On Error Resume Next
>
> If Not wdDoc Is Nothing Then
> wdDoc.Close
> Set wdDoc = Nothing
> End If
>
> If Not wdApp Is Nothing Then
> wdApp.Quit
> Set wdApp = Nothing
> End If
>
> Exit Sub
>
> Err_Handler:
> MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
> Resume Exit_Handler
>
> End Sub
>
>
>
>
>
>[/color] | | | | re: Word Table to Access
"Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
news:c1108k$1d6crq$1@ID-205437.news.uni-berlin.de...[color=blue]
> Thanks Fletcher.
>
> I might be able to follow your VBscript(is it? or is it a VB program that
> need to be compiled?) program but will this program work for multi-line
> cells? As I mentioned in my earlier message, I can't directly[/color]
cut-and-paste[color=blue]
> the table into the excel sheet cause excel treat each line of the[/color]
multi-line[color=blue]
> cell as another row of data. Somehow excel do not know how to handle cell
> data with CR/LF character in it. Can we escape them?
>
> Thanks again[/color]
The code was actually written in Access with a form and a button named
"cmdExtract" and you could just cut and paste the code. With very minor
modifications you could cut and paste this code into a normal text file and
save it as Whatever.vbs (vbs = visual basic script) and it would run.
Perhaps better still would be to re-write the file as an hta (html
application) which gives you a nice browser-based interface to work with but
is still simply plain text files.
I don't know if newgroup participants would want to write a complete html
application for nothing, but it would not take an experienced programmer
long. You could post some more specific details about the transformation
you need, eg:
Cell A1: "Name"
Cell B1: "Address"
Cell A2: "Peter Smith"
Cell B2: "85 Station Road"
"Newbury"
"Berkshire"
"United Kingdom"
How would this translate into your Access table. What tables and field
names would you have? I see elsewhere in the thread you will have up to 3
tables per doc.
Fletcher | | | | re: Word Table to Access
Thanks Fletcher.
I have at most 3 tables per word documents. And for sure, I'd love to
understand the process instead of someone else writing the whole thing.
As I mentiond I have the following data in a word table(s)
Field1: Name text(40)
Field2: <image> jpeg
Field3: Desc memo - contain CR/LF
Field4: Note memo - contain CR/LF
e.g:
Field1 Field 2 Field3 Field4
Exa One <image1> A candy in a glass On top of
refrigerator
jar.
next to the cabinet
Exa Tw0 <image2> Car with broken In the garage by
windshield and flat John
John's garden
tire.
in Sarasota
Visually, in the word table, I have 3 rows, and 4 coloumns(12 cells). The
first row is the label, and the 2nd & 3rd row are the data. If you notice,
in field3 and field 4, the cell contain a multi-line(it has CR/LF at the end
of each line-- it is not the wrap around!).
Therefore, when I cut and paste them in the excel table, I end up having
6 ROWS, and 4COLS(that is 24 cells). It treat each line of field3&field4 as
another record.
My question is, how do you write a vba in word(or access or excel) to
extract those data so I will represent the correct one. That is it should
result that I have 2 rows, 4colums of data. Do we have to somewhat escaped
CR/LF on each cells?
Thanks again.
"Fletcher Arnold" <fletch@home.com> wrote in message
news:c13c5h$ril$1@sparta.btinternet.com...[color=blue]
> "Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
> news:c1108k$1d6crq$1@ID-205437.news.uni-berlin.de...[color=green]
> > Thanks Fletcher.
> >
> > I might be able to follow your VBscript(is it? or is it a VB program[/color][/color]
that[color=blue][color=green]
> > need to be compiled?) program but will this program work for multi-line
> > cells? As I mentioned in my earlier message, I can't directly[/color]
> cut-and-paste[color=green]
> > the table into the excel sheet cause excel treat each line of the[/color]
> multi-line[color=green]
> > cell as another row of data. Somehow excel do not know how to handle[/color][/color]
cell[color=blue][color=green]
> > data with CR/LF character in it. Can we escape them?
> >
> > Thanks again[/color]
>
>
> The code was actually written in Access with a form and a button named
> "cmdExtract" and you could just cut and paste the code. With very minor
> modifications you could cut and paste this code into a normal text file[/color]
and[color=blue]
> save it as Whatever.vbs (vbs = visual basic script) and it would run.
> Perhaps better still would be to re-write the file as an hta (html
> application) which gives you a nice browser-based interface to work with[/color]
but[color=blue]
> is still simply plain text files.
>
> I don't know if newgroup participants would want to write a complete html
> application for nothing, but it would not take an experienced programmer
> long. You could post some more specific details about the transformation
> you need, eg:
>
> Cell A1: "Name"
> Cell B1: "Address"
> Cell A2: "Peter Smith"
> Cell B2: "85 Station Road"
> "Newbury"
> "Berkshire"
> "United Kingdom"
>
>
> How would this translate into your Access table. What tables and field
> names would you have? I see elsewhere in the thread you will have up to 3
> tables per doc.
>
>
> Fletcher
>
>[/color] | | | | re: Word Table to Access
Fletcher,
Your code to extract data from Word tables works great. Do you also
have code to extract data from a table in the Header of a Word document?
Thanks,
Norman Scheinin norman.b.scheinin@boeing.com
Fletcher Arnold wrote:[color=blue]
>
> "Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
> news:c1108k$1d6crq$1@ID-205437.news.uni-berlin.de...[color=green]
> > Thanks Fletcher.
> >
> > I might be able to follow your VBscript(is it? or is it a VB program that
> > need to be compiled?) program but will this program work for multi-line
> > cells? As I mentioned in my earlier message, I can't directly[/color]
> cut-and-paste[color=green]
> > the table into the excel sheet cause excel treat each line of the[/color]
> multi-line[color=green]
> > cell as another row of data. Somehow excel do not know how to handle cell
> > data with CR/LF character in it. Can we escape them?
> >
> > Thanks again[/color]
>
> The code was actually written in Access with a form and a button named
> "cmdExtract" and you could just cut and paste the code. With very minor
> modifications you could cut and paste this code into a normal text file and
> save it as Whatever.vbs (vbs = visual basic script) and it would run.
> Perhaps better still would be to re-write the file as an hta (html
> application) which gives you a nice browser-based interface to work with but
> is still simply plain text files.
>
> I don't know if newgroup participants would want to write a complete html
> application for nothing, but it would not take an experienced programmer
> long. You could post some more specific details about the transformation
> you need, eg:
>
> Cell A1: "Name"
> Cell B1: "Address"
> Cell A2: "Peter Smith"
> Cell B2: "85 Station Road"
> "Newbury"
> "Berkshire"
> "United Kingdom"
>
> How would this translate into your Access table. What tables and field
> names would you have? I see elsewhere in the thread you will have up to 3
> tables per doc.
>
> Fletcher[/color] | | | | re: Word Table to Access
Fletcher,
Your code to extract data from Word tables works great. Do you also
have code to extract data from a table in the Header of a Word document?
Thanks,
Norman Scheinin norman.b.scheinin@boeing.com
Fletcher Arnold wrote:[color=blue]
>
> "Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
> news:c1108k$1d6crq$1@ID-205437.news.uni-berlin.de...[color=green]
> > Thanks Fletcher.
> >
> > I might be able to follow your VBscript(is it? or is it a VB program that
> > need to be compiled?) program but will this program work for multi-line
> > cells? As I mentioned in my earlier message, I can't directly[/color]
> cut-and-paste[color=green]
> > the table into the excel sheet cause excel treat each line of the[/color]
> multi-line[color=green]
> > cell as another row of data. Somehow excel do not know how to handle cell
> > data with CR/LF character in it. Can we escape them?
> >
> > Thanks again[/color]
>
> The code was actually written in Access with a form and a button named
> "cmdExtract" and you could just cut and paste the code. With very minor
> modifications you could cut and paste this code into a normal text file and
> save it as Whatever.vbs (vbs = visual basic script) and it would run.
> Perhaps better still would be to re-write the file as an hta (html
> application) which gives you a nice browser-based interface to work with but
> is still simply plain text files.
>
> I don't know if newgroup participants would want to write a complete html
> application for nothing, but it would not take an experienced programmer
> long. You could post some more specific details about the transformation
> you need, eg:
>
> Cell A1: "Name"
> Cell B1: "Address"
> Cell A2: "Peter Smith"
> Cell B2: "85 Station Road"
> "Newbury"
> "Berkshire"
> "United Kingdom"
>
> How would this translate into your Access table. What tables and field
> names would you have? I see elsewhere in the thread you will have up to 3
> tables per doc.
>
> Fletcher[/color] | | | | re: Word Table to Access
Norman, would you share how you extract the word table data? Perhaps you can
give me some vba samples on how to do it. Thank much.
"Norman Scheinin" <norman.b.scheinin@boeing.com> wrote in message
news:403CB887.E7381347@boeing.com...[color=blue]
> Fletcher,
>
> Your code to extract data from Word tables works great. Do you also
> have code to extract data from a table in the Header of a Word document?
>
> Thanks,
> Norman Scheinin
> norman.b.scheinin@boeing.com
>
> Fletcher Arnold wrote:[color=green]
> >
> > "Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
> > news:c1108k$1d6crq$1@ID-205437.news.uni-berlin.de...[color=darkred]
> > > Thanks Fletcher.
> > >
> > > I might be able to follow your VBscript(is it? or is it a VB program[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> > > need to be compiled?) program but will this program work for[/color][/color][/color]
multi-line[color=blue][color=green][color=darkred]
> > > cells? As I mentioned in my earlier message, I can't directly[/color]
> > cut-and-paste[color=darkred]
> > > the table into the excel sheet cause excel treat each line of the[/color]
> > multi-line[color=darkred]
> > > cell as another row of data. Somehow excel do not know how to handle[/color][/color][/color]
cell[color=blue][color=green][color=darkred]
> > > data with CR/LF character in it. Can we escape them?
> > >
> > > Thanks again[/color]
> >
> > The code was actually written in Access with a form and a button named
> > "cmdExtract" and you could just cut and paste the code. With very minor
> > modifications you could cut and paste this code into a normal text file[/color][/color]
and[color=blue][color=green]
> > save it as Whatever.vbs (vbs = visual basic script) and it would run.
> > Perhaps better still would be to re-write the file as an hta (html
> > application) which gives you a nice browser-based interface to work with[/color][/color]
but[color=blue][color=green]
> > is still simply plain text files.
> >
> > I don't know if newgroup participants would want to write a complete[/color][/color]
html[color=blue][color=green]
> > application for nothing, but it would not take an experienced programmer
> > long. You could post some more specific details about the[/color][/color]
transformation[color=blue][color=green]
> > you need, eg:
> >
> > Cell A1: "Name"
> > Cell B1: "Address"
> > Cell A2: "Peter Smith"
> > Cell B2: "85 Station Road"
> > "Newbury"
> > "Berkshire"
> > "United Kingdom"
> >
> > How would this translate into your Access table. What tables and field
> > names would you have? I see elsewhere in the thread you will have up to[/color][/color]
3[color=blue][color=green]
> > tables per doc.
> >
> > Fletcher[/color][/color] | | | | re: Word Table to Access
Fletcher, thanks for the code. I test it and it works, but there are a few
things I'd love to know how.
Instead of displaying it on the msg box, how would you insert it to the
database, say, the access or mysql database? Do I have to use ODBC? How?
Also, if one of the colums contain images, how one extract the image? Thanks
"Fletcher Arnold" <fletch@home.com> wrote in message
news:c10eop$nsv$1@hercules.btinternet.com...[color=blue]
> "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> news:c101h9$1cgk5l$1@ID-205437.news.uni-berlin.de...[color=green]
> > Hi, I was wondering if expert can give me some lite to convert my word[/color]
> table[color=green]
> > into access database.
> >
> > Note: within each cell of my word table(s), some has multi-line data in[/color]
> it.[color=green]
> > In addition, there is one row containing picture(s) as well.
> >
> > So far, what I did is doing it manually for each word docs I have.
> >
> > Select Table
> > Convert Table to Text(I use ^ character for delimiter)
> > Save it to a text file(with char substitution, and CR/LF)
> > Then, Load them to Access DB.
> >
> > Is there an easier way to do this?[/color]
>
>
> If you want to write code to do it, here is an example that just creates a
> message box for each cell in the table showing the value. This could be
> converted to create a record in Access and you could adapt it to do this[/color]
for[color=blue]
> a number of documents, each with 1 or more tables.
> Is this a route you might pursue?
>
>
> Private Sub cmdExtract_Click()
>
> On Error GoTo Err_Handler
>
> Dim strPath As String
> Dim strValue As String
> Dim wdApp As Object 'Word.Application
> Dim wdDoc As Object 'Word.Document
> Dim wdTbl As Object 'Word.Table
> Dim wdRow As Object 'Word.Row
> Dim wdCol As Object 'Word.Column
> Dim wdCell As Object 'Word.Cell
>
> strPath = "C:\Example.doc"
>
> Set wdApp = CreateObject("Word.Application")
>
> Set wdDoc = wdApp.Documents.Open(strPath)
>
> If wdDoc.Tables.Count > 0 Then
>
> Set wdTbl = wdDoc.Tables(1)
>
> For Each wdRow In wdTbl.Rows
>
> For Each wdCol In wdTbl.Columns
>
> strValue = wdTbl.Cell(wdRow.Index, wdCol.Index).Range.Text
>
> If Len(strValue) > 2 Then
> strValue = Left$(strValue, Len(strValue) - 2)
> Else
> strValue = ""
> End If
>
> MsgBox strValue
>
> Next wdCol
>
> Next wdRow
>
> End If
>
> MsgBox "Done", vbInformation
>
> Exit_Handler:
>
> On Error Resume Next
>
> If Not wdDoc Is Nothing Then
> wdDoc.Close
> Set wdDoc = Nothing
> End If
>
> If Not wdApp Is Nothing Then
> wdApp.Quit
> Set wdApp = Nothing
> End If
>
> Exit Sub
>
> Err_Handler:
> MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
> Resume Exit_Handler
>
> End Sub
>
>
>
>
>
>[/color] | | | | re: Word Table to Access
"Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
news:c1irh5$1go9g6$1@ID-205437.news.uni-berlin.de...[color=blue]
> Fletcher, thanks for the code. I test it and it works, but there are a few
> things I'd love to know how.
>
> Instead of displaying it on the msg box, how would you insert it to the
> database, say, the access or mysql database? Do I have to use ODBC? How?[/color]
If you can give me a while, I will post a more complete example.
Fletcher | | | | re: Word Table to Access
I tweaked Fletcher's code so you can write the Word table info to your
database...
Option Compare Database
Private Sub cmdExtract_Click()
On Error GoTo Err_Handler
Dim strPath As String
Dim strValue As String
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim wdTbl As Object 'Word.Table
Dim wdRow As Object 'Word.Row
Dim wdCol As Object 'Word.Column
Dim wdCell As Object 'Word.Cell
'--NEW STUFF
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynamic)
'"mytable" is the name of the table in your DB you'll be writing to
strPath = "C:\Example.doc"
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(strPath)
If wdDoc.Tables.Count > 0 Then
Set wdTbl = wdDoc.Tables(1)
'--Row is analogous to Access Record
For Each wdRow In wdTbl.Rows
'--Column is analogous to Access Table Field
rs.AddNew
For Each wdCol In wdTbl.Columns
strValue = wdTbl.Cell(wdRow.Index,
wdCol.Index).Range.Text
If Len(strValue) > 2 Then
strValue = Left$(strValue, Len(strValue) - 2)
rs.Fields(wdCol.Index) = strValue
Else
strValue = ""
End If
MsgBox strValue
Next wdCol
'end of the column/record, so save it
rs.Update
Next wdRow
End If
rs.Close
Set rs = Nothing
MsgBox "Done", vbInformation
Exit_Handler:
On Error Resume Next
If Not wdDoc Is Nothing Then
wdDoc.Close
Set wdDoc = Nothing
End If
If Not wdApp Is Nothing Then
wdApp.Quit
Set wdApp = Nothing
End If
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
(Apologies for bollixing up your code, Fletcher)
Pieter | | | | re: Word Table to Access
Thank you, Fletcher.
"Fletcher Arnold" <fletch@home.com> wrote in message
news:c1ivca$e8t$1@sparta.btinternet.com...[color=blue]
> "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> news:c1irh5$1go9g6$1@ID-205437.news.uni-berlin.de...[color=green]
> > Fletcher, thanks for the code. I test it and it works, but there are a[/color][/color]
few[color=blue][color=green]
> > things I'd love to know how.
> >
> > Instead of displaying it on the msg box, how would you insert it to the
> > database, say, the access or mysql database? Do I have to use ODBC? How?[/color]
>
>
> If you can give me a while, I will post a more complete example.
>
> Fletcher
>
>[/color] | | | | re: Word Table to Access
"Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
news:c1ku11$1k12ov$1@ID-205437.news.uni-berlin.de...[color=blue]
> Thank you, Fletcher.
>
> "Fletcher Arnold" <fletch@home.com> wrote in message
> news:c1ivca$e8t$1@sparta.btinternet.com...[color=green]
> > "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> > news:c1irh5$1go9g6$1@ID-205437.news.uni-berlin.de...[color=darkred]
> > > Fletcher, thanks for the code. I test it and it works, but there are a[/color][/color]
> few[color=green][color=darkred]
> > > things I'd love to know how.
> > >
> > > Instead of displaying it on the msg box, how would you insert it to[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > database, say, the access or mysql database? Do I have to use ODBC?[/color][/color][/color]
How?[color=blue][color=green]
> >
> >
> > If you can give me a while, I will post a more complete example.
> >
> > Fletcher[/color][/color]
On the basis that the OP wanted to know how to get the code to run, I
thought I would offer a solution which only requires Notepad to create a
working application, provided certain system components are in place. These
components should be present if you have a reasonably up-to-date Windows
installation - so it shouldn't need any fiddling around with.
To get the data into Access, open up any normal text editor (eg NotePad) and
copy and paste the code into a new file and save the file as "Xtractor.hta"
The .hta extension is for a html application.
The code was really just for a bit of fun - to try out these hta files. One
plus side is that I can post plain text to the newsgroup, but there are a
number of downsides, including error handling. If posting attachments were
allowed, I am sure an Access/VBA/DAO solution would be better than the
VBS/ADO code posted here.
Anyway, feel free to try it out and let me know how you get on.
Fletcher
Copy everything below the stars:
' ************************************************
<html>
<head>
<title>Table Extractor</title>
<script language="vbscript">
<!--
Sub DoMain()
Dim lngMaxCols
Dim strFolder
Dim strDbName
Dim strDbPath
Dim strMsg
strFolder = document.all.txtFolder.value
If Right(strFolder,1) <> "\" Then
strFolder = strFolder & "\"
End If
If Not FolderExists(strFolder) Then
Msgbox "Non-existant Folder"
Exit Sub
End If
If CountWordDocs(strFolder) < 1 Then
Msgbox "No Word Docs"
Exit Sub
End If
strDbName = document.all.txtDbName.value
strDbPath = strFolder & strDbName
If FileExists(strDbPath) = True Then
strMsg = "The following file already exists:"
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Do you want to overwrite it?"
If Msgbox(strMsg, vbExclamation OR vbYesNoCancel) <> vbYes Then
Exit Sub
End If
If Not DeleteFile(strDbPath) Then
strMsg = "Error deleting file"
strMsg = strMsg & vbCrLf
strMsg = strMsg & "Check the file is not in use."
MsgBox strMsg, vbCritical
Exit Sub
End If
End If
If IsNumeric(document.all.txtMaxColumns.value) Then
lngMaxCols = Clng(document.all.txtMaxColumns.value)
Else
Msgbox "Columns"
Exit Sub
End If
If (lngMaxCols < 1) OR (lngMaxCols > 200) Then
Msgbox "Columns"
Exit sub
End If
If CreateDb(strDbPath, lngMaxCols) = False Then
Msgbox "Error Creating Database", vbCritical
Exit Sub
End If
ImportDocs strFolder, strDbPath, lngMaxCols
strMsg = "Word tables successfully imported" & vbCrLf
strMsg = strMsg & "Do you want to open the database?"
If Msgbox(strMsg, vbInformation OR vbYesNoCancel) = vbYes Then
StartDb(strDbPath)
End If
End Sub
Function CleanString(strDirty)
Dim strClean
Dim lng
strClean = Trim(strDirty)
If Len(strClean) > 0 Then
strClean = Replace(strClean, Chr(13), vbCrLf)
For lng = Len(strClean) To 1 Step -1
If Asc(Mid(strClean, lng, 1)) > 32 Then
Exit For
End If
Next
strClean = Left(strClean, lng)
End If
If Len(strClean) > 255 Then
strClean = Left(strClean, 250) & "..."
End If
CleanString = strClean
End Function
Function FolderExists(strFolder)
On Error Resume Next
Dim fso
Dim fld
FolderExists = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strFolder)
If Err.Number = 0 Then FolderExists = True
Set fld = Nothing
Set fso = Nothing
End Function
Function FileExists(strPath)
On Error Resume Next
Dim fso
Dim fil
FileExists = False
Set fso = CreateObject("Scripting.FileSystemObject")
Set fil = fso.GetFile(strPath)
If Err.Number = 0 Then FileExists = True
Set fil = Nothing
Set fso = Nothing
End Function
Function DeleteFile(strPath)
On Error Resume Next
Dim fso
DeleteFile = False
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile strPath, True
If Err.Number = 0 Then DeleteFile = True
Set fso = Nothing
End Function
Sub StartDb(strDbPath)
Dim wshShell
Dim lng
Set wshShell = CreateObject("WScript.Shell")
lng = wshShell.Run(strDbPath, 1)
Set wshShell = Nothing
End Sub
Function CountWordDocs(strFolder)
On Error Resume Next
Dim fil
Dim lng
lng = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strFolder)
If Err.Number = 0 Then
For each fil in fld.Files
If Right(fil.Name, 4) = ".doc" Then
lng = lng + 1
End If
Next
End If
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
CountWordDocs = lng
End Function
Sub SetFolder()
Dim strFolder
strFolder = BrowseFolder("Choose a folder", &h0007, "c:\")
If Len(strFolder)>0 Then
document.all.txtFolder.value = strFolder
End If
End Sub
Function BrowseFolder(sPrompt, BrowseInfo, root)
On Error Resume Next
Dim oShell
Dim oFolder
Dim iColonPos
Dim oWshShell
Set oShell = CreateObject("Shell.Application")
Set oWshShell = CreateObject("WScript.Shell")
Set oFolder = oShell.BrowseForFolder(&h0&, sPrompt, BrowseInfo, root)
BrowseFolder = oFolder.ParentFolder.ParseName(oFolder.Title).Path
If Err.Number <> 0 Then
BrowseFolder = Null
If oFolder.Title = "Desktop" Then
BrowseFolder = oWshShell.SpecialFolders("Desktop")
End If
iColonPos = InStr(oFolder.Title, ":")
If iColonPos > 0 Then
BrowseFolder = Mid(oFolder.Title, iColonPos - 1, 2) & "\"
End If
End If
End Function
Function GetFolder()
Dim objShell
Dim objFolder
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.BrowseForFolder(0, "Example", 0, "" )
If (not objFolder is nothing) then
GetFolder = "X" 'objFolder.Path
Else
GetFolder = ""
End if
set objFolder = Nothing
set objShell = Nothing
End function
Sub ImportTables(wdDoc, rst, lngMaxCols)
Dim wdTbl
Dim lngTblNo
Dim wdRow
Dim wdCol
Dim strValue
lngTblNo = 0
For Each wdTbl In wdDoc.Tables
lngTblNo = lngTblNo + 1
For Each wdRow In wdTbl.Rows
rst.AddNew
rst(1) = wdDoc.path & "\" & wdDoc.Name
rst(2) = lngTblNo
rst(3) = wdRow.Index
For Each wdCol In wdTbl.Columns
strValue = wdTbl.Cell(wdRow.Index, wdCol.Index).Range.Text
strValue = CleanString(strValue)
If Len(strValue) > 0 And (wdCol.Index < (lngMaxCols + 1)) Then
rst(3 + wdCol.Index) = strValue
End If
Next
rst.Update
Next
Next
Set wdTbl = Nothing
End Sub
Sub ImportDocs(strFolder, strDbPath, lngMaxCols)
Dim strSQL
Dim strCnn
Dim cnn
Dim rst
Dim wdApp
Dim wdDoc
Dim fso
Dim fld
Dim fil
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"
strCnn = strCnn & "Data Source=" & strDbPath
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = strCnn
cnn.Open
strSQL = "SELECT * FROM tblWordTables"
Set rst = CreateObject("ADODB.Recordset")
rst.Open strSQL, cnn, 2, 3
Set wdApp = CreateObject("Word.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strFolder)
For Each fil In fld.Files
If Right(fil.Name, 4) = ".doc" Then
Set wdDoc = wdApp.Documents.Open(fil.Path)
ImportTables wdDoc, rst, lngMaxCols
wdDoc.Close
Set wdDoc = Nothing
End If
Next
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
wdApp.Quit
Set wdApp = Nothing
rst.Close
Set rst = Nothing
cnn.Close
Set cnn = Nothing
End Sub
Function CreateTextColumn(catCatalog, tblTable, strColumnName)
On Error Resume Next
Const adVarWChar = 202
Dim col
Set col = CreateObject("ADOX.Column")
col.ParentCatalog = catCatalog
col.Name = strColumnName
col.Type = adVarWChar
col.properties("Nullable").Value = True
col.Properties("Jet OLEDB:Allow Zero Length").Value = False
tblTable.Columns.Append col
If Err.Number = 0 Then CreateTextColumn = True
Set col = Nothing
End Function
Function CreateLongColumn(catCatalog, tblTable, strColumnName)
On Error Resume Next
Const adInteger = 3
Dim col
Dim idx
Set col = CreateObject("ADOX.Column")
col.ParentCatalog = catCatalog
col.Name = strColumnName
col.Type = adInteger
tblTable.Columns.Append col
If Err.Number = 0 Then
Set col = Nothing
Set idx = CreateObject("ADOX.Index")
idx.Name = strColumnName
idx.Unique = False
Set col = CreateObject("ADOX.Column")
col.Name = strColumnName
idx.Columns.Append col
tblTable.Indexes.Append idx
If Err.Number = 0 Then
CreateLongColumn = True
End If
End If
Set idx = Nothing
Set col = Nothing
End Function
Function CreatePrimaryKey(catCatalog, tblTable, strColumnName)
On Error Resume Next
Const adInteger = 3
Dim col
Set col = CreateObject("ADOX.Column")
col.ParentCatalog = catCatalog
col.Name = strColumnName
col.Type = adInteger
col.Properties("AutoIncrement").Value = True
tblTable.Columns.Append col
If Err.Number = 0 Then
tblTable.Keys.Append "PrimaryKey", 1, strColumnName
If Err.Number = 0 Then
CreatePrimaryKey = True
End If
End If
Set col = Nothing
End Function
Function CreateDb(strPath, lngMaxCols)
On Error Resume Next
Dim cat
Dim tbl
Dim col
Dim str
Dim strColName
Dim lngColCount
CreateDb = True
Set cat = CreateObject("ADOX.Catalog")
str = "Provider=Microsoft.Jet.OLEDB.4.0;"
str = str & "Jet OLEDB:Engine Type=5;"
str = str & "Data Source=" & strPath
cat.Create str
If Err.Number <> 0 Then Exit Function
Set tbl = CreateObject("ADOX.Table")
tbl.ParentCatalog = cat
tbl.Name = "tblWordTables"
If Not CreatePrimaryKey(cat, tbl, "ID") Then Exit Function
If Not CreateTextColumn(cat, tbl, "DocPath") Then Exit Function
If Not CreateLongColumn(cat, tbl, "TableNo") Then Exit Function
If Not CreateLongColumn(cat, tbl, "RowNo") Then Exit Function
For lngColCount = 1 to lngMaxCols
strColName = Cstr(1000 + lngColCount)
strColName = "Column" & Mid(strColName, 2)
If Not CreateTextColumn(cat, tbl, strColName) Then
Exit Function
End If
Next
cat.Tables.Append tbl
If Err.Number = 0 Then
CreateDb = True
Else
Msgbox Err.Description
End If
Set tbl = Nothing
Set cat = Nothing
End Function
-->
</script>
<body bgcolor="#CCCCFF">
<table>
<th colspan="2" align="center">Extract Tables From Microsoft Word</th>
<tr><td> </td><td> </td></tr>
<tr>
<td>Document Folder</td>
<td><input type="text" id="txtFolder" value="C:\"</td>
</tr>
<tr>
<td>Database Name</td>
<td><input type="text" id="txtDbName" value="WordTables.mdb"</td>
</tr>
<tr>
<td>Maximum Columns</td>
<td><input type="text" id="txtMaxColumns" value="10"</td>
</tr>
<tr><td> </td><td> </td></tr>
<tr>
<td><input type="button" name="cmdFolder" value="Change Folder"
onclick="SetFolder()"></td>
<td><input type="button" name="cmdImport" value="Import Tables"
onclick="DoMain()"></td>
</tr>
</table>
</body>
</html> | | | | re: Word Table to Access
"Pieter Linden" <pietlinden@hotmail.com> wrote in message
news:bf31e41b.0402251706.3d085d8d@posting.google.c om...[color=blue]
> I tweaked Fletcher's code so you can write the Word table info to your
> database...
>[/color]
<snip>[color=blue]
> (Apologies for bollixing up your code, Fletcher)
>
> Pieter[/color]
Hi Pieter
By all means feel free. It's an open forum and is sometimes a relief when
others answer your posts. If you are interested in what I finally did with
it have a look at my post elsewhere in this thread. This shows an html
application with VBS/ADO which was done to see if I could post a plain text
file with all the necessary code.
Fletcher | | | | re: Word Table to Access
"Norman Scheinin" <norman.b.scheinin@boeing.com> wrote in message
news:403CB8A0.B729F19C@boeing.com...[color=blue]
> Fletcher,
>
> Your code to extract data from Word tables works great. Do you also
> have code to extract data from a table in the Header of a Word document?
>
> Thanks,
> Norman Scheinin
> norman.b.scheinin@boeing.com[/color]
Hi Norman
It is simply a case of navigating your way through Word's object model to
get at what you want. I am not an expert on long documents created in Word,
but I tested this little snippet to get some info out of a table in the
header of a simple Word document.
If you have more complicated documents, headers can be different for
odd/even pages, for different sections, etc but this might give you a start
so you can start to have a more thorough investigation of the Word object
model.
Set wdHdr = wdDoc.Sections(1).Headers(wdHeaderFooterPrimary)
If wdHdr.Range.Tables.Count > 0 Then
Set wdTbl = wdHdr.Range.Tables(1)
MsgBox wdTbl.Cell(2, 2).Range.Text
Set wdTbl = Nothing
End If
Set wdHdr = Nothing
Fletcher | | | | re: Word Table to Access
Hi Fletcher, thanks for posting the code.
How do you execute Xtractor.hta file?
When use IE6, it prompt me with a form(which I filed in) but without
'submit' button to execute. Perhaps I overlook something ...
Thanks again.
"Fletcher Arnold" <fletch@home.com> wrote in message
news:c1l97r$fe$1@hercules.btinternet.com...[color=blue]
> "Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
> news:c1ku11$1k12ov$1@ID-205437.news.uni-berlin.de...[color=green]
> > Thank you, Fletcher.
> >
> > "Fletcher Arnold" <fletch@home.com> wrote in message
> > news:c1ivca$e8t$1@sparta.btinternet.com...[color=darkred]
> > > "Ruby Tuesday" <rubytuzdayz@yahoo.com> wrote in message
> > > news:c1irh5$1go9g6$1@ID-205437.news.uni-berlin.de...
> > > > Fletcher, thanks for the code. I test it and it works, but there are[/color][/color][/color]
a[color=blue][color=green]
> > few[color=darkred]
> > > > things I'd love to know how.
> > > >
> > > > Instead of displaying it on the msg box, how would you insert it to[/color][/color]
> the[color=green][color=darkred]
> > > > database, say, the access or mysql database? Do I have to use ODBC?[/color][/color]
> How?[color=green][color=darkred]
> > >
> > >
> > > If you can give me a while, I will post a more complete example.
> > >
> > > Fletcher[/color][/color]
>
>
> On the basis that the OP wanted to know how to get the code to run, I
> thought I would offer a solution which only requires Notepad to create a
> working application, provided certain system components are in place.[/color]
These[color=blue]
> components should be present if you have a reasonably up-to-date Windows
> installation - so it shouldn't need any fiddling around with.
>
> To get the data into Access, open up any normal text editor (eg NotePad)[/color]
and[color=blue]
> copy and paste the code into a new file and save the file as[/color]
"Xtractor.hta"[color=blue]
> The .hta extension is for a html application.
>
> The code was really just for a bit of fun - to try out these hta files.[/color]
One[color=blue]
> plus side is that I can post plain text to the newsgroup, but there are a
> number of downsides, including error handling. If posting attachments[/color]
were[color=blue]
> allowed, I am sure an Access/VBA/DAO solution would be better than the
> VBS/ADO code posted here.
>
> Anyway, feel free to try it out and let me know how you get on.
>
> Fletcher
>
>
>
> Copy everything below the stars:
> ' ************************************************
>
> <html>
> <head>
> <title>Table Extractor</title>
> <script language="vbscript">
> <!--
>
> Sub DoMain()
>
> Dim lngMaxCols
> Dim strFolder
> Dim strDbName
> Dim strDbPath
> Dim strMsg
>
> strFolder = document.all.txtFolder.value
>
> If Right(strFolder,1) <> "\" Then
> strFolder = strFolder & "\"
> End If
>
> If Not FolderExists(strFolder) Then
> Msgbox "Non-existant Folder"
> Exit Sub
> End If
>
> If CountWordDocs(strFolder) < 1 Then
> Msgbox "No Word Docs"
> Exit Sub
> End If
>
> strDbName = document.all.txtDbName.value
>
> strDbPath = strFolder & strDbName
>
> If FileExists(strDbPath) = True Then
>
> strMsg = "The following file already exists:"
> strMsg = strMsg & vbCrLf
> strMsg = strMsg & "Do you want to overwrite it?"
>
> If Msgbox(strMsg, vbExclamation OR vbYesNoCancel) <> vbYes Then
> Exit Sub
> End If
>
> If Not DeleteFile(strDbPath) Then
> strMsg = "Error deleting file"
> strMsg = strMsg & vbCrLf
> strMsg = strMsg & "Check the file is not in use."
> MsgBox strMsg, vbCritical
> Exit Sub
> End If
> End If
>
> If IsNumeric(document.all.txtMaxColumns.value) Then
> lngMaxCols = Clng(document.all.txtMaxColumns.value)
> Else
> Msgbox "Columns"
> Exit Sub
> End If
>
> If (lngMaxCols < 1) OR (lngMaxCols > 200) Then
> Msgbox "Columns"
> Exit sub
> End If
>
> If CreateDb(strDbPath, lngMaxCols) = False Then
> Msgbox "Error Creating Database", vbCritical
> Exit Sub
> End If
>
> ImportDocs strFolder, strDbPath, lngMaxCols
>
> strMsg = "Word tables successfully imported" & vbCrLf
> strMsg = strMsg & "Do you want to open the database?"
>
> If Msgbox(strMsg, vbInformation OR vbYesNoCancel) = vbYes Then
> StartDb(strDbPath)
> End If
>
> End Sub
>
>
>
>
> Function CleanString(strDirty)
>
> Dim strClean
> Dim lng
>
> strClean = Trim(strDirty)
>
> If Len(strClean) > 0 Then
>
> strClean = Replace(strClean, Chr(13), vbCrLf)
>
> For lng = Len(strClean) To 1 Step -1
> If Asc(Mid(strClean, lng, 1)) > 32 Then
> Exit For
> End If
> Next
>
> strClean = Left(strClean, lng)
> End If
>
> If Len(strClean) > 255 Then
> strClean = Left(strClean, 250) & "..."
> End If
>
> CleanString = strClean
>
> End Function
>
>
>
>
> Function FolderExists(strFolder)
>
> On Error Resume Next
>
> Dim fso
> Dim fld
>
> FolderExists = False
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> Set fld = fso.GetFolder(strFolder)
>
> If Err.Number = 0 Then FolderExists = True
>
> Set fld = Nothing
>
> Set fso = Nothing
>
> End Function
>
>
>
>
> Function FileExists(strPath)
>
> On Error Resume Next
>
> Dim fso
> Dim fil
>
> FileExists = False
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> Set fil = fso.GetFile(strPath)
>
> If Err.Number = 0 Then FileExists = True
>
> Set fil = Nothing
>
> Set fso = Nothing
>
> End Function
>
>
>
>
> Function DeleteFile(strPath)
>
> On Error Resume Next
>
> Dim fso
>
> DeleteFile = False
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> fso.DeleteFile strPath, True
>
> If Err.Number = 0 Then DeleteFile = True
>
> Set fso = Nothing
>
> End Function
>
>
>
>
> Sub StartDb(strDbPath)
>
> Dim wshShell
> Dim lng
>
> Set wshShell = CreateObject("WScript.Shell")
>
> lng = wshShell.Run(strDbPath, 1)
>
> Set wshShell = Nothing
>
> End Sub
>
>
>
>
> Function CountWordDocs(strFolder)
>
> On Error Resume Next
>
> Dim fil
> Dim lng
>
> lng = 0
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> Set fld = fso.GetFolder(strFolder)
>
> If Err.Number = 0 Then
>
> For each fil in fld.Files
>
> If Right(fil.Name, 4) = ".doc" Then
> lng = lng + 1
> End If
> Next
>
> End If
>
> Set fil = Nothing
>
> Set fld = Nothing
>
> Set fso = Nothing
>
> CountWordDocs = lng
>
> End Function
>
>
>
>
> Sub SetFolder()
>
> Dim strFolder
>
> strFolder = BrowseFolder("Choose a folder", &h0007, "c:\")
>
> If Len(strFolder)>0 Then
> document.all.txtFolder.value = strFolder
> End If
>
> End Sub
>
>
>
>
> Function BrowseFolder(sPrompt, BrowseInfo, root)
>
> On Error Resume Next
>
> Dim oShell
> Dim oFolder
> Dim iColonPos
> Dim oWshShell
>
> Set oShell = CreateObject("Shell.Application")
>
> Set oWshShell = CreateObject("WScript.Shell")
>
> Set oFolder = oShell.BrowseForFolder(&h0&, sPrompt, BrowseInfo, root)
>
> BrowseFolder = oFolder.ParentFolder.ParseName(oFolder.Title).Path
>
> If Err.Number <> 0 Then
>
> BrowseFolder = Null
>
> If oFolder.Title = "Desktop" Then
> BrowseFolder = oWshShell.SpecialFolders("Desktop")
> End If
>
> iColonPos = InStr(oFolder.Title, ":")
>
> If iColonPos > 0 Then
> BrowseFolder = Mid(oFolder.Title, iColonPos - 1, 2) & "\"
> End If
> End If
>
> End Function
>
>
>
>
> Function GetFolder()
>
> Dim objShell
> Dim objFolder
>
> set objShell = CreateObject("Shell.Application")
>
> set objFolder = objShell.BrowseForFolder(0, "Example", 0, "" )
>
> If (not objFolder is nothing) then
> GetFolder = "X" 'objFolder.Path
> Else
> GetFolder = ""
> End if
>
> set objFolder = Nothing
> set objShell = Nothing
>
> End function
>
>
>
>
> Sub ImportTables(wdDoc, rst, lngMaxCols)
>
> Dim wdTbl
> Dim lngTblNo
> Dim wdRow
> Dim wdCol
> Dim strValue
>
> lngTblNo = 0
>
> For Each wdTbl In wdDoc.Tables
>
> lngTblNo = lngTblNo + 1
>
> For Each wdRow In wdTbl.Rows
>
> rst.AddNew
> rst(1) = wdDoc.path & "\" & wdDoc.Name
> rst(2) = lngTblNo
> rst(3) = wdRow.Index
>
> For Each wdCol In wdTbl.Columns
>
> strValue = wdTbl.Cell(wdRow.Index, wdCol.Index).Range.Text
>
> strValue = CleanString(strValue)
>
> If Len(strValue) > 0 And (wdCol.Index < (lngMaxCols + 1)) Then
> rst(3 + wdCol.Index) = strValue
> End If
>
> Next
>
> rst.Update
>
> Next
>
> Next
>
> Set wdTbl = Nothing
>
> End Sub
>
>
>
>
> Sub ImportDocs(strFolder, strDbPath, lngMaxCols)
>
> Dim strSQL
> Dim strCnn
> Dim cnn
> Dim rst
> Dim wdApp
> Dim wdDoc
> Dim fso
> Dim fld
> Dim fil
>
> strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"
> strCnn = strCnn & "Data Source=" & strDbPath
>
> Set cnn = CreateObject("ADODB.Connection")
>
> cnn.ConnectionString = strCnn
>
> cnn.Open
>
> strSQL = "SELECT * FROM tblWordTables"
>
> Set rst = CreateObject("ADODB.Recordset")
>
> rst.Open strSQL, cnn, 2, 3
>
> Set wdApp = CreateObject("Word.Application")
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> Set fld = fso.GetFolder(strFolder)
>
> For Each fil In fld.Files
>
> If Right(fil.Name, 4) = ".doc" Then
>
> Set wdDoc = wdApp.Documents.Open(fil.Path)
>
> ImportTables wdDoc, rst, lngMaxCols
>
> wdDoc.Close
>
> Set wdDoc = Nothing
>
> End If
> Next
>
> Set fil = Nothing
> Set fld = Nothing
> Set fso = Nothing
> wdApp.Quit
> Set wdApp = Nothing
> rst.Close
> Set rst = Nothing
> cnn.Close
> Set cnn = Nothing
> End Sub
>
>
>
>
> Function CreateTextColumn(catCatalog, tblTable, strColumnName)
>
> On Error Resume Next
>
> Const adVarWChar = 202
> Dim col
>
> Set col = CreateObject("ADOX.Column")
> col.ParentCatalog = catCatalog
> col.Name = strColumnName
> col.Type = adVarWChar
> col.properties("Nullable").Value = True
> col.Properties("Jet OLEDB:Allow Zero Length").Value = False
>
> tblTable.Columns.Append col
>
> If Err.Number = 0 Then CreateTextColumn = True
>
> Set col = Nothing
>
> End Function
>
>
>
>
> Function CreateLongColumn(catCatalog, tblTable, strColumnName)
>
> On Error Resume Next
>
> Const adInteger = 3
> Dim col
> Dim idx
>
> Set col = CreateObject("ADOX.Column")
> col.ParentCatalog = catCatalog
> col.Name = strColumnName
> col.Type = adInteger
>
> tblTable.Columns.Append col
>
> If Err.Number = 0 Then
>
> Set col = Nothing
>
> Set idx = CreateObject("ADOX.Index")
>
> idx.Name = strColumnName
>
> idx.Unique = False
>
> Set col = CreateObject("ADOX.Column")
>
> col.Name = strColumnName
>
> idx.Columns.Append col
>
> tblTable.Indexes.Append idx
>
> If Err.Number = 0 Then
>
> CreateLongColumn = True
>
> End If
>
> End If
>
> Set idx = Nothing
>
> Set col = Nothing
>
> End Function
>
>
> Function CreatePrimaryKey(catCatalog, tblTable, strColumnName)
>
> On Error Resume Next
>
> Const adInteger = 3
> Dim col
>
> Set col = CreateObject("ADOX.Column")
> col.ParentCatalog = catCatalog
> col.Name = strColumnName
> col.Type = adInteger
> col.Properties("AutoIncrement").Value = True
>
> tblTable.Columns.Append col
>
> If Err.Number = 0 Then
>
> tblTable.Keys.Append "PrimaryKey", 1, strColumnName
>
> If Err.Number = 0 Then
>
> CreatePrimaryKey = True
>
> End If
>
> End If
>
> Set col = Nothing
>
> End Function
>
>
> Function CreateDb(strPath, lngMaxCols)
>
> On Error Resume Next
> Dim cat
> Dim tbl
> Dim col
> Dim str
> Dim strColName
> Dim lngColCount
>
> CreateDb = True
>
> Set cat = CreateObject("ADOX.Catalog")
>
> str = "Provider=Microsoft.Jet.OLEDB.4.0;"
> str = str & "Jet OLEDB:Engine Type=5;"
> str = str & "Data Source=" & strPath
>
> cat.Create str
>
> If Err.Number <> 0 Then Exit Function
>
> Set tbl = CreateObject("ADOX.Table")
>
> tbl.ParentCatalog = cat
>
> tbl.Name = "tblWordTables"
>
> If Not CreatePrimaryKey(cat, tbl, "ID") Then Exit Function
>
> If Not CreateTextColumn(cat, tbl, "DocPath") Then Exit Function
>
> If Not CreateLongColumn(cat, tbl, "TableNo") Then Exit Function
>
> If Not CreateLongColumn(cat, tbl, "RowNo") Then Exit Function
>
> For lngColCount = 1 to lngMaxCols
>
> strColName = Cstr(1000 + lngColCount)
>
> strColName = "Column" & Mid(strColName, 2)
>
> If Not CreateTextColumn(cat, tbl, strColName) Then
> Exit Function
> End If
> Next
>
> cat.Tables.Append tbl
>
> If Err.Number = 0 Then
> CreateDb = True
> Else
> Msgbox Err.Description
> End If
>
> Set tbl = Nothing
>
> Set cat = Nothing
>
> End Function
>
> -->
> </script>
>
> <body bgcolor="#CCCCFF">
>
> <table>
> <th colspan="2" align="center">Extract Tables From Microsoft Word</th>
>
> <tr><td> </td><td> </td></tr>
>
> <tr>
> <td>Document Folder</td>
> <td><input type="text" id="txtFolder" value="C:\"</td>
> </tr>
>
> <tr>
> <td>Database Name</td>
> <td><input type="text" id="txtDbName" value="WordTables.mdb"</td>
> </tr>
>
> <tr>
> <td>Maximum Columns</td>
> <td><input type="text" id="txtMaxColumns" value="10"</td>
> </tr>
>
> <tr><td> </td><td> </td></tr>
>
> <tr>
> <td><input type="button" name="cmdFolder" value="Change Folder"
> onclick="SetFolder()"></td>
> <td><input type="button" name="cmdImport" value="Import Tables"
> onclick="DoMain()"></td>
> </tr>
>
> </table>
>
> </body>
> </html>
>
>
>[/color] | | | | re: Word Table to Access
"Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
news:c1movi$1kje1r$1@ID-205437.news.uni-berlin.de...[color=blue]
> Hi Fletcher, thanks for posting the code.
> How do you execute Xtractor.hta file?
> When use IE6, it prompt me with a form(which I filed in) but without
> 'submit' button to execute. Perhaps I overlook something ...
>
> Thanks again.
>[/color]
You fill in 3 things:
1: The folder where your Word documents are stored. The program imports
all tables from all documents in that folder, so if you only want a few
documents done, you could move them to their own folder first. This will
also be the folder where the MS Access database is created. You can type
the folder path e.g C:\MyStuff or use the "change folder" button.
2: The name of the database - which might as well be left as
"WordTables.mdb"
3: The maximum number of columns which will be imported from each Word
table into the database.
**The final step is to press the "Import Tables" button which should firstly
create a new Access db for the results (or prompt you to overwrite an
existing one). It then takes each table in each Word document in the
specified folder and imports the contents into the new database. When it
has finished, it gives you the chance to open the database immediately.
That is the theory, anyway and it did work perfectly on my machine, although
it does take a while for large numbers of tables. Or did you already press
the import button and something didn't work?
Fletcher | | | | re: Word Table to Access
Hi Fletcher,
when I ran the Xtractor.hta, it and set the correct folder path and the
access db, it keeps telling me that the folder is 'Non-Existant'.
I also try to hardcoded the path, and came back the same error. Did I
overlook something? Thanks
"Fletcher Arnold" <fletch@home.com> wrote in message
news:c1msdn$khm$1@titan.btinternet.com...[color=blue]
>
> "Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
> news:c1movi$1kje1r$1@ID-205437.news.uni-berlin.de...[color=green]
> > Hi Fletcher, thanks for posting the code.
> > How do you execute Xtractor.hta file?
> > When use IE6, it prompt me with a form(which I filed in) but without
> > 'submit' button to execute. Perhaps I overlook something ...
> >
> > Thanks again.
> >[/color]
>
> You fill in 3 things:
>
> 1: The folder where your Word documents are stored. The program imports
> all tables from all documents in that folder, so if you only want a few
> documents done, you could move them to their own folder first. This will
> also be the folder where the MS Access database is created. You can type
> the folder path e.g C:\MyStuff or use the "change folder" button.
>
> 2: The name of the database - which might as well be left as
> "WordTables.mdb"
>
> 3: The maximum number of columns which will be imported from each Word
> table into the database.
>
> **The final step is to press the "Import Tables" button which should[/color]
firstly[color=blue]
> create a new Access db for the results (or prompt you to overwrite an
> existing one). It then takes each table in each Word document in the
> specified folder and imports the contents into the new database. When it
> has finished, it gives you the chance to open the database immediately.
>
> That is the theory, anyway and it did work perfectly on my machine,[/color]
although[color=blue]
> it does take a while for large numbers of tables. Or did you already[/color]
press[color=blue]
> the import button and something didn't work?
>
>
> Fletcher
>
>
>
>
>[/color] | | | | re: Word Table to Access
"Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
news:c1nosn$1kr92q$1@ID-205437.news.uni-berlin.de...[color=blue]
> Hi Fletcher,
> when I ran the Xtractor.hta, it and set the correct folder path and[/color]
the[color=blue]
> access db, it keeps telling me that the folder is 'Non-Existant'.[/color]
Are you giving the name of an existing folder where the Word documents are?
What happens if you place an example Word document in the root folder (C:\)
so you do not touch the default settings of the form?
If you want to speed up communications, let me know an e-mail address and
I'll send you mine.
Fletcher | | | | re: Word Table to Access
Nope. No luck. I gives me the same error.
here's my email:
-- please remove the dash(-) and colon(:) in the email address:
ruby-tuz:daiz@yahoo.com
Thanks
"Fletcher Arnold" <fletch@home.com> wrote in message
news:c1np9v$t6n$1@hercules.btinternet.com...[color=blue]
> "Ruby Tuesday" <rubytuezdayz@yahoo.com> wrote in message
> news:c1nosn$1kr92q$1@ID-205437.news.uni-berlin.de...[color=green]
> > Hi Fletcher,
> > when I ran the Xtractor.hta, it and set the correct folder path and[/color]
> the[color=green]
> > access db, it keeps telling me that the folder is 'Non-Existant'.[/color]
>
>
> Are you giving the name of an existing folder where the Word documents[/color]
are?[color=blue]
> What happens if you place an example Word document in the root folder[/color]
(C:\)[color=blue]
> so you do not touch the default settings of the form?
>
> If you want to speed up communications, let me know an e-mail address and
> I'll send you mine.
>
>
> Fletcher
>
>[/color] | | | | re: Word Table to Access
Fletcher,
just a thought... You could use the BrowseFolder API from mvps.org
and then just let the user browse for the folder... Makes it a bit
more flexible, that's all. | | | | re: Word Table to Access
Pieter -
In your message of 2004-02-25, you included the code below. Whenever I
try to run it in Access 97, I get the error "3001" invalid argument.
When I try to run it in Access 2002, I get the error "Compile Error:
User-defined type not defined.
If you have the time, can you suggest what might be going wrong? FYI, I
do have the table "mytable" in the DB.
Thanks,
Patrick
************************************************** ********
Option Compare Database
Private Sub cmdExtract_Click()
On Error GoTo Err_Handler
Dim strPath As String
Dim strValue As String
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim wdTbl As Object 'Word.Table
Dim wdRow As Object 'Word.Row
Dim wdCol As Object 'Word.Column
Dim wdCell As Object 'Word.Cell
'--NEW STUFF
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynamic)
'"mytable" is the name of the table in your DB you'll be writing to
strPath = "C:\Example.doc"
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(strPath)
If wdDoc.Tables.Count > 0 Then
Set wdTbl = wdDoc.Tables(1)
'--Row is analogous to Access Record
For Each wdRow In wdTbl.Rows
'--Column is analogous to Access Table Field
rs.AddNew
For Each wdCol In wdTbl.Columns
strValue =
wdTbl.Cell(wdRow.Index,wdCol.Index).Range.Text
If Len(strValue) > 2 Then
strValue = Left$(strValue, Len(strValue) - 2)
rs.Fields(wdCol.Index) = strValue
Else
strValue = ""
End If
MsgBox strValue
Next wdCol
'end of the column/record, so save it
rs.Update
Next wdRow
End If
rs.Close
Set rs = Nothing
MsgBox "Done", vbInformation
Exit_Handler:
On Error Resume Next
If Not wdDoc Is Nothing Then
wdDoc.Close
Set wdDoc = Nothing
End If
If Not wdApp Is Nothing Then
wdApp.Quit
Set wdApp = Nothing
End If
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
***********************************************
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! | | | | re: Word Table to Access
RE/[color=blue]
>When I try to run it in Access 2002, I get the error "Compile Error:
>User-defined type not defined.[/color]
Have you declared a reference to Word (code window, Tools|References)?
--
PeteCresswell | | | | re: Word Table to Access
Thanks, Pete -
I just did, and now in 2K I'm getting the aforementioned Error No:
3001 Invalid Argument.
Still stumped. I've found a couple of notes in the MSKB, but they are
a bit..uh..cloudy to me - for example:
SYMPTOMS
Some data access objects in Visual Basic for Windows version 4.0 no
longer have the default "Name" property. Instead, these objects now
have a default collection. This change can lead to "Type Mismatch"
(Error 13) or "Invalid Argument" (Error 3001) errors when attempting
to run your code.
WORKAROUND
To work around this problem, add the name of the property you want to
reference.
For example, use this: MsgBox Data1.Database.TableDefs(0).Name
instead of this: MsgBox Data1.Database.TablesDefs(0)
Am I missing something obvious?
Patrick
"(Pete Cresswell)" <x@y.z> wrote in message news:<kr2pl09ault1erp3o02rr9ntu6a2c8c628@4ax.com>. ..[color=blue]
> RE/[color=green]
> >When I try to run it in Access 2002, I get the error "Compile Error:
> >User-defined type not defined.[/color]
>
> Have you declared a reference to Word (code window, Tools|References)?[/color] | | | | re: Word Table to Access
RE/[color=blue]
>Am I missing something obvious?[/color]
How about posting the line of code it's barfing on ....plus some more lines
before/after?
--
PeteCresswell | | | | re: Word Table to Access
Thanks, Pete -
Code below - I'm not getting a specific indication of where the error
is occuring (not sure how I would do that), but given the way the code
has been developed by those who posted it, I'm guessing it's in one of
the lines annotated with "'NEW".
Option Compare Database
Private Sub Command2_Click()
On Error GoTo Err_Handler
Dim strPath As String
Dim strValue As String
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim wdTbl As Object 'Word.Table
Dim wdRow As Object 'Word.Row
Dim wdCol As Object 'Word.Column
Dim wdCell As Object 'Word.Cell
'*******START***************
'--BEGIN NEW STUFF
Dim rs As DAO.Recordset 'NEW
Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynamic) 'NEW
'"mytable" is the name of the table in your DB you'll be writing to
strPath = "C:\Example.doc"
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open(strPath)
If wdDoc.Tables.Count > 0 Then
Set wdTbl = wdDoc.Tables(1)
'--Row is analogous to Access Record
For Each wdRow In wdTbl.Rows
'--Column is analogous to Access Table Field
rs.AddNew 'NEW
For Each wdCol In wdTbl.Columns
strValue = wdTbl.Cell(wdRow.Index,
wdCol.Index).Range.Text
If Len(strValue) > 2 Then
strValue = Left$(strValue, Len(strValue) - 2)
rs.Fields(wdCol.Index) = strValue 'NEW
Else
strValue = ""
End If
MsgBox strValue
Next wdCol
'end of the column/record, so save it
rs.Update 'NEW
Next wdRow
End If
rs.Close 'NEW
Set rs = Nothing 'NEW
MsgBox "Done", vbInformation 'NEW
Exit_Handler:
On Error Resume Next
If Not wdDoc Is Nothing Then
wdDoc.Close
Set wdDoc = Nothing
End If
If Not wdApp Is Nothing Then
wdApp.Quit
Set wdApp = Nothing
End If
If Not rs Is Nothing Then 'NEW
rs.Close 'NEW
Set rs = Nothing 'NEW
End If
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub
"(Pete Cresswell)" <x@y.z> wrote in message news:<ohorl09nb8ijf4qikct64dd7aap43fb2m3@4ax.com>. ..[color=blue]
> RE/[color=green]
> >Am I missing something obvious?[/color]
>
> How about posting the line of code it's barfing on ....plus some more lines
> before/after?[/color] | | | | re: Word Table to Access
RE/[color=blue]
>I'm guessing it's in one of
>the lines annotated with "'NEW".[/color]
Why guess? Add line numbers to the code and amend the error trap to something
like:
MsgBox Err.Description, vbExclamation, "Line " & Erl & " :Error " & Err.Number &
" " & Error$ & "'."
--
PeteCresswell | | | | re: Word Table to Access
RE/[color=blue]
>Why guess? Add line numbers....[/color]
Alternatively, Rem out "On Error GoTo Err_Handler" and
it will stop on the problem line.
--
PeteCresswell | | | | re: Word Table to Access
Thanks, Pete.
I moved the code back to A97 so I could use wzComment to add line
numbers (not experienced enough with 2K to know how to do it there)
and added your suggested error trapping code.
Turns out the offending line is:
Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynamic)
Does that tell anyone anything? It's greek to me...
I tried being more specific by replacing "Current.DB" with the name of
my database, and then I get an error (in A97 or A02) saying;
"Method or Data Member not found"
I'm stumped.
Thanks again.
Patrick Arkins
"(Pete Cresswell)" <x@y.z> wrote in message news:<ck86m09hk8ljpadohi29n0vfmlhqkhkibe@4ax.com>. ..[color=blue]
> RE/[color=green]
> >I'm guessing it's in one of
> >the lines annotated with "'NEW".[/color]
>
> Why guess? Add line numbers to the code and amend the error trap to something
> like:
>
> MsgBox Err.Description, vbExclamation, "Line " & Erl & " :Error " & Err.Number &
> " " & Error$ & "'."[/color] | | | | re: Word Table to Access
On 6 Oct 2004 06:46:53 -0700, melted1@butter.toast.net (Patrick Arkins) wrote:
[color=blue]
>Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynamic)[/color]
Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynaset)
Wayne Gillespie
Gosford NSW Australia | | | | re: Word Table to Access
(Pete Cresswell) wrote:[color=blue]
> RE/
>[color=green]
>>Why guess? Add line numbers....[/color]
>
>
> Alternatively, Rem out "On Error GoTo Err_Handler" and
> it will stop on the problem line.
>[/color]
Using a simple error handler as an example, this is what I do:
<---
ErrHandler:
Msgbox Err.Description
Resume ErrExit
Resume
--->
Break into the code on the Msgbox, then Ctrl+F9 on the last line
(Resume), F8 will take you back to the offending line. That way there's
no danger of changing your code for debugging and forgetting to change
it back again for release.
--
Pretentious? Moi? | | | | re: Word Table to Access
Wayne Gillespie <bestfit@NObestfitsoftwareSPAM.com.au> wrote in message news:<qg08m0hfac2r55f323hcv3vsgs0ftqp11g@4ax.com>. ..[color=blue]
> On 6 Oct 2004 06:46:53 -0700, melted1@butter.toast.net (Patrick Arkins) wrote:
>[color=green]
> >Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynamic)[/color]
>
> Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynaset)
>
> Wayne Gillespie
> Gosford NSW Australia[/color]
Thanks Wayne... that's the trouble with knocking out answers off the
top of your head... simple stupid things... OOPS! I stand corrected
(in the corner, with the rest of the ne'er-do-wells...) | | | | re: Word Table to Access
RE/[color=blue]
>no danger of changing your code for debugging and forgetting to change
>it back again for release.[/color]
I like it.
Thanks.
--
PeteCresswell | | | | re: Word Table to Access
Fletcher, Wayne, Piet -
Back to working on this, trying to get the HTA to work for my
purposes, having determined it's closer to meeting my needs than the
Access Code (no offense intended). Thanks for the help so far.
Here's where things stand:
HTA Method:
The HTA method chews through a folder of .DOC files nicely, and builds
the tables well with one exception; What seems to be my only
remaining challenge is that one of my table cells contains > 255
characters 98% of the time. I understand the purpose of Function
CleanString(strDirty), but I need the entire string. Is there a way
in the HTA to specify that the field should be a memo field, or some
other way to safely stash a thousand or so characters?
Access Code:
I'm facing several challenges with the Access code - note: these are
NOT meant to be criticisms. Just an explanation of why I think the
HTA is closer to meeting my needs. If anyone has an idea of how I can
fix these issues, I'm all ears.
1. The Access code runs on a specific file, (Eaxample.doc) not a
folder of files like the HTA. I've got 1,000 files to process, and
don't see how to do it without editing the form code each time.
2. The Access code seems not to capture the DocPath info, which is
very helpful for me when I need a way to identify what records are
coming from where.
3. The Access code stops between tables, and my documents have 3. The
HTA code motors on.
4. Access 97 (which I assume the code is designed to run in) doesn't
like the fact that I have tables with varying numbers of columns - it
stops the process altogether. The HTA doesn't seem to mind. (Of
course, I have to do some cleaning up of the tables once I've run the
HTA, and some fun queries, but only once.)
Thanks for any suggestions.
Patrick pietlinden@hotmail.com (Pieter Linden) wrote in message news:<bf31e41b.0410061336.548ca64a@posting.google. com>...[color=blue]
> Wayne Gillespie <bestfit@NObestfitsoftwareSPAM.com.au> wrote in message news:<qg08m0hfac2r55f323hcv3vsgs0ftqp11g@4ax.com>. ..[color=green]
> > On 6 Oct 2004 06:46:53 -0700, melted1@butter.toast.net (Patrick Arkins) wrote:
> >[color=darkred]
> > >Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynamic)[/color]
> >
> > Set rs = CurrentDb.OpenRecordset("mytable", dbOpenDynaset)
> >
> > Wayne Gillespie
> > Gosford NSW Australia[/color]
>
> Thanks Wayne... that's the trouble with knocking out answers off the
> top of your head... simple stupid things... OOPS! I stand corrected
> (in the corner, with the rest of the ne'er-do-wells...)[/color] | | | | re: Word Table to Access
Fletcher, Wayne, Piet -
Back to working on this, trying to get the HTA to work for my
purposes, having determined it's closer to meeting my needs than the
Access Code (no offense intended). Thanks for the help so far.
Here's where things stand:
HTA Method:
The HTA method chews through a folder of .DOC files nicely, and builds
the tables well with one exception; What seems to be my only
remaining challenge is that one of my table cells contains > 255
characters 98% of the time. I understand the purpose of Function
CleanString(strDirty), but I need the entire string. Is there a way
in the HTA to specify that the field should be a memo field, or some
other way to safely stash a thousand or so characters?
Access Code:
I'm facing several challenges with the Access code - note: these are
NOT meant to be criticisms. Just an explanation of why I think the
HTA is closer to meeting my needs. If anyone has an idea of how I can
fix these issues, I'm all ears.
1. The Access code runs on a specific file, (Eaxample.doc) not a
folder of files like the HTA. I've got 1,000 files to process, and
don't see how to do it without editing the form code each time.
2. The Access code seems not to capture the DocPath info, which is
very helpful for me when I need a way to identify what records are
coming from where.
3. The Access code stops between tables, and my documents have 3. The
HTA code motors on.
4. Access 97 (which I assume the code is designed to run in) doesn't
like the fact that I have tables with varying numbers of columns - it
stops the process altogether. The HTA doesn't seem to mind. (Of
course, I have to do some cleaning up of the tables once I've run the
HTA, and some fun queries, but only once.)
Thanks for any suggestions.
Patrick
************************************************** ***************************** |  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,411 network members.
|