Link to home
Start Free TrialLog in
Avatar of craig20120
craig20120

asked on

Word Plugin w/ MFC / ATL - How to modify text contents of active document.

I have a MS Word plugin using MFC and ATL.  I know how to get a pointer to the Word active document.  I can save the document, etc., but how can I get access to the text contents of that document to modify it then save it.

Thanks!!
Avatar of AlexNek
AlexNek

You need to search class Selection or Range
...
"Use the InsertAfter or InsertBefore method to insert text before or after a Selection or Range object. The following example inserts text at the end of the active document."
...

It can be /VBA code/
Set doc = ActiveDocument
Set rngRange = _
    doc.Range(doc.Paragraphs(1).Start,  doc.Paragraphs(1).End - 1)
rngRange.InsertAfter _
    " This is now the last sentence in paragraph one."


http://support.microsoft.com/default.aspx/kb/222101
http://www.codeguru.com/cpp/misc/misc/article.php/c6091/
Avatar of craig20120

ASKER

Question...  "It can be VBA code".  Is that a question or a statement??  I don't know how to call VBA code from C++.  

Thanks!


ASKER CERTIFIED SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, I can use those functions.  Not sure of the syntax though.  Do you have the C++ code.
No, I haven't C++ cod.e It can be something like that:

CRange* rngRange = pDocumentt->Range(pDocumentt->Paragraphs(1)->Start(),  pDocumentt->Paragraphs(1)->End() - 1);

rngRange->InsertAfter(" This is now the last sentence in paragraph one.");
Does rngRange represent the actual word document itself?   In other words, if I save it to a database, I can read it back out again??  

Thanks!!
Disregard, the last comment.  Thanks for your help.