Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Embed and automate a Word document with MFC

57 views
Skip to first unread message

emcz

unread,
Jun 25, 2010, 2:58:24 PM6/25/10
to
Following link
http://support.microsoft.com/kb/238611
has a good sample to embed and automate a word document with MFC.

However, I can not use this sample to open an existing Word document.
I am wondering if some one can give me some help here.

I am also wondering if I can do this, open an existing word document and copy
all contents into the new word document created in the above sample.

I can not find any copy function in _Document or Documents, those 2 classes
are
generated from word type library.

TIA for any help.

emcz

Joseph M. Newcomer

unread,
Jun 25, 2010, 3:27:54 PM6/25/10
to
If you are looking for copy-and-paste, sure, this doesn't work, because it involves a
CreateNewItem call to create a new document.

Have you thought of looking for a function that opens an existing document?
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer

unread,
Jun 25, 2010, 3:41:30 PM6/25/10
to
By the way, the code shown in that example violates a lot of the principles of exceptions
we've been discussing in another thread; for example, the really horrible

TRY
{
...
if(...)
//Any exception will do. You just need to break out of the
//TRY statement
AfxThrowMemoryException();

CATCH(CException, e)
{
}
END_CATCH

The use of the obsolete macros shows that this example has not been updated in decades.

It is probably an error to catch CException (as opposed to the expected COleException*
that will be thrown), and the use of a throw immediately contained inside a try has been
discussed as an exceptionally (pun intended) bad practice. The slovenliness of throwing
"any old exception" and having a catch that catches any exception is particularly
offensive.

Looks like another "summer intern" code example written without adult supervision. And
another really good example for my "Bad MSDN Examples" series.
joe

On Fri, 25 Jun 2010 11:58:24 -0700, emcz <em...@discussions.microsoft.com> wrote:

emcz

unread,
Jun 25, 2010, 4:42:20 PM6/25/10
to

Documents class has an 'Open' function, but it can not be used in this sample.
Because either COleClientItem::CreateNewItem or COleClientItem::DoVerb call
creates a _Document.


"Joseph M. Newcomer" wrote:

> .
>

0 new messages