Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-04-05
7
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

715 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