Solved

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

Posted on 2007-04-05
7
306 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

739 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