Re: Type mismatch error when opening word doc using automation

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I would suggest showing the actual type mismatch error, and possibly the prototype of the
Open method; it would help a lot. Also the prototype for COleVariant; are you sure there
is a version that takes an LPCSTR (as opposed to an LPCTSTR, or possibly an LPWSTR or a
BSTR)
joe

On Thu, 24 Apr 2008 12:38:55 -0700 (PDT), mtuzhilov@xxxxxxxxx wrote:

I get a Type Mismatch error when trying to open word file by using
automation. I am using msword.h header from Office 2007 and compiling
with VC++ 6.0.


CoInitialize(0);

_Application oWord ;
Documents oDocs;
_Document oDoc;
COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR); //For optional args

//Start Word
if(!(oWord.CreateDispatch("Word.Application", NULL)))

{
AfxMessageBox("Error starting Word.", MB_SETFOREGROUND);
return 0;
}


//Open a document
oDocs = oWord.GetDocuments();

//error happens on this line
oDoc = oDocs.Open(COleVariant("C:\\PROJECTS\\RRD_OFFICE2007\
\test.rtf"), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt,
vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt);

Does any one have an idea?

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


Quantcast