Click here to Skip to main content
15,882,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I'm using VS 2005 and MFC (no .Net please)
I need to scan through a bunch of MS Word documents (.DOC, .DOCX) and find all the documents that have a given keyword inside them or a number of keywords.

How can I write such code, that will return to me a list of the paths to the Word documents where that keyword is found or an empty list if none were found.

Cheers,
Alex
Posted
Updated 13-Feb-11 11:52am
v2
Comments
[no name] 14-Feb-11 1:50am    
I won't post this as answer but rather as a comment, since it's not very elegant, but maybe useful to you anyway.
.doc files contain all text without encoding, you could just perform a search as if it were a text file. For .docx files this won't work however.

May be you will find this CP article helpful: MS Office OLE Automation Using C++[^]

I don't know if the article will answer your question, but it may lead you to the right direction.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Feb-11 17:59pm    
I don't mind if OP uses it, a 5.
--SA
You can use Word's automation API to do this, but you'll quickly find that there is almost no documentation for C++/COM anymore. MSDN seems to only have the .NET interop API documented, and if your Google skills are good, you may be able to get the older MSDN pages, but even those would only have VB6 examples. Since you want to avoid .NET I assume your C++ and COM skills are good. If so, you should be able to put together some code based on the VB and .NET documentation out there.

Here's a decent article from 2004 that shows how to access the Word API from VC++ :

http://support.microsoft.com/kb/238393[^]

Use that article to get started with how you can get going with C++ and COM. Once you get that working take a look at this article:

How to: Search for Text in Documents[^]

That article is for .NET but once you've got COM access, the method/property names would be the same. So you can just convert that to equivalent C++ code, and that should be what it takes to do what you are trying to do.

Good luck!
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 13-Feb-11 18:00pm    
Automation. Sure, OP can do it, my 5.
--SA
AlexEvans 14-Feb-11 3:48am    
Hi Nish,
All the samples provided in the article you suggested have the "C++" section with the following comment - This language is not supported or no code example is available.
I am only able to understand (sort of...) something in C++

Thanks anyway
Alex
Nish Nishant 14-Feb-11 8:26am    
Well, go through the C# examples, the syntax will be nearly identical to C++. All you need are the method/property names to use.
Yes, please.
—SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Feb-11 18:05pm    
Ha-ha! (about down-voting)
Read the question!
I mean, read the original question, how it was formulated at the moment of answering.
I don't want to change my answer, it's right to the point.


--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900