472,982 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

C++ Word automation Extract text

Sub: C++ Word automation Extract text


I want extact text form a word document using a visual c++ programme.

I have see a lot of documentation. and my analysis is that I must use a
"word automation".

I have foud a lot of exemple to use it but I need your precious help to
use it properly.

I init my automation

CLSID clsid;
CLSIDFromProgID(L"Word.Application", &clsid);

IUnknown* pUnk;
HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_LOCAL_SERVER,
IID_IUnknown, (void**) &pUnk);
if (FAILED(hr))
OutputDebugString("Error in creating Word application instance\n");
return -1;

hr = pUnk->QueryInterface(IID_IDispatch, (void**)&m_pDispApp);

DISPPARAMS dp = { NULL, NULL, 0, 0 };
LPOLESTR szDoc = L"Documents";
IDispatch* pDocuments = NULL;
VARIANT varRetVal;
hr = m_pDispApp->GetIDsOfNames(IID_NULL, &szDoc, 1,
hr = m_pDispApp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
if (!SUCCEEDED(hr))
return -1;

m_pDocuments = varRetVal.pdispVal;
I open a word document

VARIANT varRetVal;
EXCEPINFO excepInfo; // this variable contains exception info if any
Invoke call fails
varg.vt = VT_BSTR;
varg.bstrVal = _bstr_t(strFilePath); // this is the MS-word document
filename, must be changed to a valid filename that

exists on disk
DISPPARAMS dpOpen = { &varg, NULL, 1, 0 };
DISPID dispOpenID;
LPOLESTR szOpenDoc = L"Open";
HRESULT hr = m_pDocuments->GetIDsOfNames(IID_NULL, &szOpenDoc, 1,
hr = m_pDocuments->Invoke(dispOpenID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, &dpOpen, &varRetVal, &excepInfo,

if (FAILED(hr))
OutputDebugString("Error opening the document\n");
return -1;

a ms word programme open, <b>i dont want to see the MS Word application
to open</b>

How to read the word file w/o having the MSWord interface poping up ?
2. if the document is used, then, i see a message box that asks me to
chose between read-only, notifiy ..

I always have to open it as readonly (how can do this ?)
3. I have found how to save a doc document in txt file

VARIANT vNeuerName, vSpeichernFormat;
vNeuerName.vt = VT_BSTR;
vNeuerName.bstrVal = SysAllocString(L"C:\\delete\\docneu.txt");
vSpeichernFormat.vt = VT_I4;
vSpeichernFormat.lVal = 2;


IDispatch* pDocument = varRetVal.pdispVal;
DISPPARAMS dpSave = { NULL, NULL, 0, 0 };
DISPID dispSaveID;
LPOLESTR szSaveDoc = L"SaveAs";

hr = pDocument->GetIDsOfNames(IID_NULL, &szSaveDoc, 1,
hr = pDocument->Invoke(dispSaveID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, &dpSave, &varRetVal, NULL, NULL);

But this code is invalid. Why ?

4. I only have to read the text from the .doc file and I would like to
avoid saving it in a other file
(how can do it ?)

Many Thank you for your help.

Visual C++ programmer.

Oct 3 '05 #1
1 11953
mi********@gmail.com wrote:
Sub: C++ Word automation Extract text


I want extact text form a word document using a visual c++ programme.


This is off-topic in this newsgroup, which is concerned with standard
C++ only. Try a Microsoft-specific group like

Cheers! --M

Oct 3 '05 #2

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

Similar topics

by: Ptaku25 | last post by:
Hello All, I would like to insert some text in specific location in MS Word document under app written in BCB6, location of the document I mean that I want to insert some text eg. after...
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
by: Richard Grene | last post by:
using Word automation from vb.net how can I get to the bottom of the document? Thanks, Richard
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
by: teo | last post by:
hallo, I need to extract a word and few text that precedes and follows it (about 30 + 30 chars) from a long textual document. Like the description that Google returns when it has found a...
by: liya.tansky | last post by:
Hello, I'm developing an intranet (win XP, .NET 2, Visual Studio 2005, Microsoft.Office.Interop.Word.dll in references) and needed to implement find-replace in word doc before sending letter and...
by: Paul Mc | last post by:
Hi all, It's a little late in the day for me so please forgive as i need my bed.!! The issue is i need to open a word doc (say "c:\temp.doc) and paste into it, but i only can work out how...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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

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