Solved

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

Posted on 2007-04-05
7
302 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
ID: 18863125
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
ID: 18863152
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
ID: 18863223
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:craig20120
ID: 18865159
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
ID: 18885498
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
ID: 18886025
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
ID: 18886040
Disregard, the last comment.  Thanks for your help.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

920 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

12 Experts available now in Live!

Get 1:1 Help Now