- Local time
- Today, 17:36
- Joined
- Feb 28, 2001
- Messages
- 30,558
This is kind of long, but I've been working on it for a while and getting headaches. Here is what has been going on...
I am building a database to help me analyze some large Word documents that contain references to certain key words. I am developing in the AC97/Word97 environment. The documents are designed with a master-document/sub-document structure. More than one such document exists at the moment, each with between 16 and 22 chapters. The shortest document has a word count in excess of 120,000. The longest is over 160,000.
The goal of this exercise is a table that will contain a keyword index, document index, and chapter index for each case where the keyword appears in a chapter of the document. My report will show me chapters where the keyword is referenced. In other words, a cross-reference of keyword to chapter. I'm storing index numbers because I have lookup tables for each item and only need to store the indexes in order to build the final report.
The process is being controlled by a form in Access. Code in the class module of the form drives the relevant file scans, Word activation, etc. off a command button. Breakpoints confirm that the button kicks off the scanning procedure.
I open the Word document using the CreateObject method for "Application.Word" followed by the .Open method on the separate chapter document. This becomes my ActiveDocument in Word context. The local debug window confirms that there are times when the Word app object is open and has some number of paragraphs. The paragraph count is reasonable for the given document, though I haven't actually sat down and counted paragraphs. If I open Word through another window, I find that my document is visible from the Menu Bar's Window drop-down. Therefore I am quite sure that the file is being opened and closed through Word.
Where I come into grief is when I try to implement the cross-reference scanner that searches text. In general, I have tried several different approaches. The idea is that for
objWordDoc.Paragraphs(loPghNum).Range.Text
I want to find if a particular word exists in that paragraph. The words I seek come from a table. I have verified that the proper names are readable through the recordsets I use to feed the scanner module. (Again, using a breakpoint to look at variables at various parts of the scan.) So I know I'm looking for a non-null bit of text.
I have tried the Word Find object using .Paragraphs(index).Find with the proper name or keyword as an input to the find. The .Find parameters were set so the search was limited to the range of that paragraph. I.e. it is either in that paragraph or not. Since I am visiting each paragraph in turn, I don't want the search going outside the paragraph's range until I tell it to do so.
Anyway, after the .Find.Execute, I check the Found property - but it doesn't seem to find anything. I.e. .Found is always false even if I open the document directly and read the paragraph. There is the name I am seeking, big as life! And the .Find input was valid, too. Well, I got frustrated when that didn't work worth a poop.
So then I tried copying each paragraph in turn to a string so I could try an Instr function. But I opened the document read-only and it is telling me that
stRange = objWordDoc.Paragraph(index).Range.Text
won't work because the document is read-only. Well OF COURSE it is read-only. I don't want to edit it, I just want to read it. When I try to open the document with ReadOnly = false, I get another error because (get set to barf...) the REAL documents are in WordPerfect. I am opening the documents with automatic, silent conversion to Word but do not want to save anything!
So then I tried to do a .Copy of the paragraph and .Paste the text into a (invisible) text box. Well, ...Paragraph(index).Copy works great according to the Clipboard. But the Access text box doesn't seem to understand the .Paste or .PasteSpecial methods. (Yes, before you ask, Word and Office references are checked and not MISSING in my references list.) Is there something else I should have checked in Tools>>References to define .Paste or .PasteSpecial operations?
My Developer's Handbook Library (Access volume OR Office volume) isn't being very helpful here so far. Does anyone have any suggestions on where to go next?
All I really want is for Access to read the lousy document a paragraph at the time, search the text for keywords in my list, and make notes when it finds them. How hard can that be? (Obviously, given the above tale of woe, harder than it looks.)
I am building a database to help me analyze some large Word documents that contain references to certain key words. I am developing in the AC97/Word97 environment. The documents are designed with a master-document/sub-document structure. More than one such document exists at the moment, each with between 16 and 22 chapters. The shortest document has a word count in excess of 120,000. The longest is over 160,000.
The goal of this exercise is a table that will contain a keyword index, document index, and chapter index for each case where the keyword appears in a chapter of the document. My report will show me chapters where the keyword is referenced. In other words, a cross-reference of keyword to chapter. I'm storing index numbers because I have lookup tables for each item and only need to store the indexes in order to build the final report.
The process is being controlled by a form in Access. Code in the class module of the form drives the relevant file scans, Word activation, etc. off a command button. Breakpoints confirm that the button kicks off the scanning procedure.
I open the Word document using the CreateObject method for "Application.Word" followed by the .Open method on the separate chapter document. This becomes my ActiveDocument in Word context. The local debug window confirms that there are times when the Word app object is open and has some number of paragraphs. The paragraph count is reasonable for the given document, though I haven't actually sat down and counted paragraphs. If I open Word through another window, I find that my document is visible from the Menu Bar's Window drop-down. Therefore I am quite sure that the file is being opened and closed through Word.
Where I come into grief is when I try to implement the cross-reference scanner that searches text. In general, I have tried several different approaches. The idea is that for
objWordDoc.Paragraphs(loPghNum).Range.Text
I want to find if a particular word exists in that paragraph. The words I seek come from a table. I have verified that the proper names are readable through the recordsets I use to feed the scanner module. (Again, using a breakpoint to look at variables at various parts of the scan.) So I know I'm looking for a non-null bit of text.
I have tried the Word Find object using .Paragraphs(index).Find with the proper name or keyword as an input to the find. The .Find parameters were set so the search was limited to the range of that paragraph. I.e. it is either in that paragraph or not. Since I am visiting each paragraph in turn, I don't want the search going outside the paragraph's range until I tell it to do so.
Anyway, after the .Find.Execute, I check the Found property - but it doesn't seem to find anything. I.e. .Found is always false even if I open the document directly and read the paragraph. There is the name I am seeking, big as life! And the .Find input was valid, too. Well, I got frustrated when that didn't work worth a poop.
So then I tried copying each paragraph in turn to a string so I could try an Instr function. But I opened the document read-only and it is telling me that
stRange = objWordDoc.Paragraph(index).Range.Text
won't work because the document is read-only. Well OF COURSE it is read-only. I don't want to edit it, I just want to read it. When I try to open the document with ReadOnly = false, I get another error because (get set to barf...) the REAL documents are in WordPerfect. I am opening the documents with automatic, silent conversion to Word but do not want to save anything!
So then I tried to do a .Copy of the paragraph and .Paste the text into a (invisible) text box. Well, ...Paragraph(index).Copy works great according to the Clipboard. But the Access text box doesn't seem to understand the .Paste or .PasteSpecial methods. (Yes, before you ask, Word and Office references are checked and not MISSING in my references list.) Is there something else I should have checked in Tools>>References to define .Paste or .PasteSpecial operations?
My Developer's Handbook Library (Access volume OR Office volume) isn't being very helpful here so far. Does anyone have any suggestions on where to go next?
All I really want is for Access to read the lousy document a paragraph at the time, search the text for keywords in my list, and make notes when it finds them. How hard can that be? (Obviously, given the above tale of woe, harder than it looks.)