;/exe 1 typelibWord{00020905-0000-0000-C000-000000000046}8.0 Word.Application a._getactive;;connect to Word. On Vista/7, macro process must run as User. QM normally runs as Admin. The /exe 1 tells QM to run the macro in separate process, as User. Word.Range r
;get all text
r=a.ActiveDocument.Range str sAllText=r.Text out sAllText
;get selected text
r=a.Selection.Range str sSelText=r.Text out sSelText
;BEGIN PROJECT ;main_function Get text from MS Office Word ;END PROJECT
When I try to get text from multiple files in the file path, the program executes normally and retrieves text from all of the files. However, after retrieving the text from the last file, I get the following RT error: Error (RT) in DocSearchTest: 0x800401EA, Moniker cannot open file. ?
typelibWord{00020905-0000-0000-C000-000000000046}8.0 str files if(!inp(files "Please specify the location of the files:""TestDocRetrieve""C:\test\*.doc"))ret
Dir d1 foreach(d1 files FE_Dir);;for each file that matches the pattern.
(`i),str sPath=d1.FileName(1)
,Word.Document d._getfile(_s.expandpath(sPath)) ,Word.Range r
;get all text ,r=d.Range ,lpstr sAllText=r.Text ;;out sAllText
typelibWord{00020905-0000-0000-C000-000000000046}8.0 str files if(!inp(files "Please specify the location of the files:""TestDocRetrieve""C:\test\*.doc"))ret
Dir d1 foreach(d1 files FE_Dir);;for each file that matches the pattern. ,str sPath=d1.FileName(1) ,out sPath , ,Word.Document d._getfile(sPath) ,Word.Range r , ,;get all text ,r=d.Range ,lpstr sAllText=r.Text ,;out sAllText
It is breaking on a temporary Word file like "~$cument1.doc".
It's "parent", document1.doc is the first file from which text is retrieved.
So, I think QM is having Word keep this file open during the loop. Once the code breaks, the file is deleted and any search, hidden files included, finds no such file.
I think I should be able to work around it with a test for "~$" in the filename.
typelibWord{00020905-0000-0000-C000-000000000046}8.0 str files if(!inp(files "Please specify the location of the files:""TestDocRetrieve""C:\test"))ret
ARRAY(str) a GetFilesInFolder a files "*.doc"
int i for i 0 a.len ,out a[i] , ,Word.Document d._getfile(a[i]) ,Word.Range r , ,;get all text ,r=d.Range ,lpstr sAllText=r.Text ,;out sAllText
typelibWord{00020905-0000-0000-C000-000000000046}8.0 str files if(!inp(files "Please specify the location of the files:""TestDocRetrieve""C:\test"))ret
ARRAY(str) a GetFilesInFolder a files "*.doc"
int i for i 0 a.len ,out a[i] , ,Word.Document d._getfile(a[i]) ,Word.Range r , ,;get all text ,r=d.Range ,lpstr sAllText=r.Text ,;out sAllText
I use the above code, test failed, where is the problem ?