From: emcz on
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
From: Joseph M. Newcomer on
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

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

>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 [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
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 <emcz(a)discussions.microsoft.com> wrote:

>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 [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: emcz on
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:

> 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
>
> On Fri, 25 Jun 2010 11:58:24 -0700, emcz <emcz(a)discussions.microsoft.com> wrote:
>
> >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 [MVP]
> email: newcomer(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
> .
>