Solved

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

Posted on 2007-04-05
7
300 Views
Last Modified: 2013-11-18
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!!
0
Comment
Question by:craig20120
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:AlexNek
Comment Utility
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/
0
 

Author Comment

by:craig20120
Comment Utility
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!


0
 
LVL 16

Accepted Solution

by:
AlexNek earned 250 total points
Comment Utility
It is a statement with notice.
"It can be:"
Text
You don't need to use VBA code in C++. Try only to look into.
Can you see using of ActiveDocument.Range, ActiveDocument.Paragraph(), Range.InsertAfter()?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:craig20120
Comment Utility
Yes, I can use those functions.  Not sure of the syntax though.  Do you have the C++ code.
0
 
LVL 16

Expert Comment

by:AlexNek
Comment Utility
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.");
0
 

Author Comment

by:craig20120
Comment Utility
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!!
0
 

Author Comment

by:craig20120
Comment Utility
Disregard, the last comment.  Thanks for your help.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now